You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
- Add comprehensive CHANGELOG.md with emoji legend and organized release notes
- Update README.md with new v0.4.0 features: configuration system, Sudo.as_root DSL, graphical password prompts, and timeouts
- Document ASK_PATH_CMD constant for convenient askpass program detection
- Fix spelling errors and improve documentation clarity
- Update VERSION constant to 0.4.0-rc1 for pre-release
Copy file name to clipboardExpand all lines: README.md
+66-5Lines changed: 66 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -53,7 +53,7 @@ sudo[MyClass].my_class_method
53
53
sudo.stop!
54
54
```
55
55
56
-
A convienient utility for working with sudo is to use the `run` method and pass it a block.
56
+
A convenient utility for working with sudo is to use the `run` method and pass it a block.
57
57
Run will automatically start and stop the ruby sudo process around the block.
58
58
59
59
```ruby
@@ -66,11 +66,72 @@ end
66
66
# Sockets and processes are closed automatically when the block exits
67
67
```
68
68
69
-
Both `Sudo::Wrapper.run` and `Sudo::Wrapper.new`take the same named arguments: `ruby_opts` (default: `''` ) and `load_gems` (default: `true`).
69
+
Both `Sudo::Wrapper.run` and `Sudo::Wrapper.new`accept configuration options:
70
70
71
-
If you'd like to pass options to the sudo-spawned ruby process, pass them as a string to `ruby_opts`.
71
+
-`ruby_opts` (default: `''`) - Options to pass to the sudo-spawned ruby process
72
+
- Any configuration option can be passed to override global settings (e.g., `timeout`, `load_gems`, `socket_dir`, etc.)
72
73
73
-
If you'd like to prevent the loading of `gems` currently loaded from the calling program, pass `false` to `load_gems`. This will give your sudo process a unmodifed environment. The only things required via the sudo process are `'drb/drb'`, `'fileutils'`, and of course `'sudo'`.
74
+
If you'd like to prevent the loading of `gems` currently loaded from the calling program, pass `load_gems: false`. This will give your sudo process an unmodified environment. The only things required via the sudo process are `'drb/drb'`, `'fileutils'`, and of course `'sudo'`.
75
+
76
+
### New DSL (v0.4.0+)
77
+
78
+
For simple operations, you can use the convenience method:
79
+
80
+
```ruby
81
+
require'sudo'
82
+
83
+
# Accepts the same options as Wrapper.run:
84
+
Sudo.as_root(load_gems:false) do |sudo|
85
+
sudo[FileUtils].mkdir_p '/root/only/path'
86
+
sudo[File].write '/etc/config', content
87
+
end
88
+
```
89
+
90
+
### Configuration (v0.4.0+)
91
+
92
+
Configure global defaults:
93
+
94
+
```ruby
95
+
Sudo.configure do |config|
96
+
config.timeout =30# Default: 10 seconds
97
+
config.socket_dir ='/var/run'# Default: '/tmp'
98
+
config.sudo_askpass ='/usr/bin/ssh-askpass'# For graphical password prompts
99
+
config.load_gems =false# Default: true - whether to load current gems in sudo process
100
+
end
101
+
```
102
+
103
+
### Graphical Password Prompts (v0.4.0+)
104
+
105
+
Set `sudo_askpass` to use graphical password prompts via `sudo -A`:
106
+
107
+
```ruby
108
+
Sudo.configure do |config|
109
+
config.sudo_askpass ='/usr/bin/ssh-askpass'
110
+
# Or use the auto-detected constant for convenience:
111
+
# config.sudo_askpass = Sudo::ASK_PATH_CMD
112
+
end
113
+
114
+
# Or per-wrapper:
115
+
Sudo::Wrapper.run(sudo_askpass:'/usr/bin/ssh-askpass') do |sudo|
116
+
sudo[FileUtils].mkdir_p '/secure/path'
117
+
end
118
+
```
119
+
120
+
### Timeouts (v0.4.0+)
121
+
122
+
Configure connection timeouts:
123
+
124
+
```ruby
125
+
# Global configuration
126
+
Sudo.configure do |config|
127
+
config.timeout =15# Wait up to 15 seconds for sudo process to start
128
+
end
129
+
130
+
# Or per-wrapper
131
+
Sudo::Wrapper.run(timeout:5) do |sudo|
132
+
sudo[SomeClass].time_sensitive_operation
133
+
end
134
+
```
74
135
75
136
## Credits
76
137
@@ -88,7 +149,7 @@ Robert M. Koch ([@threadmetal](https://github.com/threadmetal))
88
149
89
150
Wolfgang Teuber ([@wteuber](https://github.com/wteuber))
90
151
91
-
### Other aknowledgements
152
+
### Other acknowledgements
92
153
93
154
94
155
Thanks to Tony Arcieri and Brian Candler for suggestions on
0 commit comments