command_mapper 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f84f3d9440979699163ef84f4fbc703cae8813a15e3fda52a7f7cb41fff1e2a0
4
- data.tar.gz: 5bd3028c74eb09a4de384a9e09a9d43405883ae1cf3c1b8f74af0ba665d45c04
3
+ metadata.gz: 64e0cd16f2f829aa5175d24e251b13b0324459f9afedc5949177a877ac73bfee
4
+ data.tar.gz: 41f4d3aa749a5844797e6e7745eef6fda781ff4cc301b561913b48d3b3dfd25e
5
5
  SHA512:
6
- metadata.gz: 0df6ae96d0550ca1ce3ab8e046538deefd6d5f2ecdd58bf8f99979c6f831c3a97acb1eff327a0c5595dfad6e7f1b88633a80175e8cdabd48bffca3c2e2be182b
7
- data.tar.gz: 68c4bbc6a908940737e1f7d6cdb1467220f621fdbc60db72eb9acb261ad9bd9118afdb184bb040b4fb6951eedc009098224f3d8908a0989e0ddeafd1a94fe116
6
+ metadata.gz: f218287281e48ae82fb3feb4120279d5a7c28455213c160adde7d7aefd67874c542227cfd3584d60150711652679f7cc8b49d6b9b3d1fc4ab7630a6486cc8432
7
+ data.tar.gz: ec718ea345aede03c9720afc88aa9fbdec4c348a6771e60de2ae41e48a4f3780fa290f93886f7091416d60cfa35b74946111bc780552de4c69f3cf6ceca0b864
@@ -9,16 +9,15 @@ jobs:
9
9
  fail-fast: false
10
10
  matrix:
11
11
  ruby:
12
- - '2.6'
13
- - '2.7'
14
12
  - '3.0'
15
13
  - '3.1'
16
14
  - '3.2'
15
+ - '3.3'
17
16
  - jruby
18
17
  - truffleruby
19
18
  name: Ruby ${{ matrix.ruby }}
20
19
  steps:
21
- - uses: actions/checkout@v2
20
+ - uses: actions/checkout@v4
22
21
  - name: Set up Ruby
23
22
  uses: ruby/setup-ruby@v1
24
23
  with:
data/.yardopts CHANGED
@@ -1 +1 @@
1
- --markup markdown --title "CommandMapper Documentation" --protected --quiet
1
+ --markup markdown --title "CommandMapper Documentation" --protected
data/ChangeLog.md CHANGED
@@ -1,3 +1,11 @@
1
+ ### 0.3.2 / 2024-01-23
2
+
3
+ * Switch to use `require_relative` to improve load-times.
4
+ * Allow passing `sudo` specific keyword arguments in
5
+ {CommandMapper::Command#sudo_command} to {CommandMapper::Sudo.run}.
6
+ * Allow {CommandMapper::Sudo}'s `preserve_env` attribute to accept an optional
7
+ value.
8
+
1
9
  ### 0.3.1 / 2022-12-25
2
10
 
3
11
  * Use `File.exist?` in {CommandMapper::Types::InputPath#validate} for Ruby
data/LICENSE.txt CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2021-2022 Hal Brodigan
1
+ Copyright (c) 2021-2024 Hal Brodigan
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -353,6 +353,41 @@ Grep.sudo(patterns: "Error", file: "/var/log/syslog")
353
353
  # ...
354
354
  ```
355
355
 
356
+ ### Defining sub-commands
357
+
358
+ ```ruby
359
+ module Git
360
+ class Command < CommandMapper::Command
361
+
362
+ command 'git' do
363
+ option "--version"
364
+ option "--help"
365
+ option "-C", name: :dir, value: {type: InputDir.new}
366
+ # ...
367
+
368
+ subcommand :clone do
369
+ option "--bare"
370
+ option "--mirror"
371
+ option "--depth", value: {type: Num.new}
372
+ # ...
373
+
374
+ argument :repository
375
+ argument :directory, required: false
376
+ end
377
+
378
+ # ...
379
+ end
380
+
381
+ end
382
+ end
383
+ ```
384
+
385
+ ### Invoking sub-commands
386
+
387
+ ```ruby
388
+ Git::Command.run(clone: {repository: 'https://github.com/user/repo.git'})
389
+ ```
390
+
356
391
  ### Code Gen
357
392
 
358
393
  [command_mapper-gen] can automatically generate command classes from a command's
@@ -390,6 +425,18 @@ class Cat < CommandMapper::Command
390
425
  end
391
426
  ```
392
427
 
428
+ ### Real-World Examples
429
+
430
+ * [ruby-nmap](https://github.com/postmodern/ruby-nmap#readme)
431
+ * [ruby-masscan](https://github.com/postmodern/ruby-masscan#readme)
432
+ * [ruby-amass](https://github.com/postmodern/ruby-amass#readme)
433
+ * [ruby-yasm](https://github.com/postmodern/ruby-yasm#readme)
434
+ * [ruby-ncrack](https://github.com/postmodern/ruby-ncrack#readme)
435
+ * [ruby-nikto](https://github.com/postmodern/ruby-nikto#readme)
436
+ * [ruby-gobuster](https://github.com/postmodern/ruby-gobuster#readme)
437
+ * [ruby-feroxbuster](https://github.com/postmodern/ruby-feroxbuster#readme)
438
+ * [ruby-rustscan](https://github.com/postmodern/ruby-rustscan#readme)
439
+
393
440
  ## Requirements
394
441
 
395
442
  * [ruby] >= 2.0.0
@@ -412,6 +459,10 @@ gem 'command_mapper', '~> 0.2'
412
459
  gemspec.add_dependency 'command_mapper', '~> 0.2'
413
460
  ```
414
461
 
462
+ ## Alternatives
463
+
464
+ * [terrapin](https://github.com/thoughtbot/terrapin#readme)
465
+
415
466
  ## License
416
467
 
417
468
  Copyright (c) 2021-2022 Hal Brodigan
@@ -7,10 +7,7 @@ Gem::Specification.new do |gem|
7
7
 
8
8
  gem.name = gemspec.fetch('name')
9
9
  gem.version = gemspec.fetch('version') do
10
- lib_dir = File.join(File.dirname(__FILE__),'lib')
11
- $LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
12
-
13
- require 'command_mapper/version'
10
+ require_relative 'lib/command_mapper/version'
14
11
  CommandMapper::VERSION
15
12
  end
16
13
 
data/gemspec.yml CHANGED
@@ -14,7 +14,7 @@ metadata:
14
14
  documentation_uri: https://rubydoc.info/gems/command_mapper
15
15
  source_code_uri: https://github.com/postmodern/command_mapper.rb
16
16
  bug_tracker_uri: https://github.com/postmodern/command_mapper.rb/issues
17
- changelog_uri: https://github.com/postmodern/command_mapper.rb/blob/master/ChangeLog.md
17
+ changelog_uri: https://github.com/postmodern/command_mapper.rb/blob/main/ChangeLog.md
18
18
  rubygems_mfa_required: 'true'
19
19
 
20
20
  required_ruby_version: ">= 2.0.0"
@@ -1,5 +1,5 @@
1
- require 'command_mapper/types/type'
2
- require 'command_mapper/types/str'
1
+ require_relative 'types/type'
2
+ require_relative 'types/str'
3
3
 
4
4
  module CommandMapper
5
5
  #
@@ -1,5 +1,5 @@
1
- require 'command_mapper/exceptions'
2
- require 'command_mapper/arg'
1
+ require_relative 'exceptions'
2
+ require_relative 'arg'
3
3
 
4
4
  module CommandMapper
5
5
  #
@@ -1,6 +1,6 @@
1
- require 'command_mapper/types'
2
- require 'command_mapper/argument'
3
- require 'command_mapper/option'
1
+ require_relative 'types'
2
+ require_relative 'argument'
3
+ require_relative 'option'
4
4
 
5
5
  require 'shellwords'
6
6
 
@@ -50,8 +50,8 @@ module CommandMapper
50
50
  # Custom environment variables to pass to the command.
51
51
  #
52
52
  # @param [Hash{Symbol => Object}] kwargs
53
- # Additional keywords arguments. These will be used to populate
54
- # {#options} and {#arguments}, along with `params`.
53
+ # Additional keywords arguments. These will be used to populate the
54
+ # command's `params`.
55
55
  #
56
56
  # @yield [self]
57
57
  # The newly initialized command.
@@ -92,8 +92,8 @@ module CommandMapper
92
92
  # The option and argument values.
93
93
  #
94
94
  # @param [Hash{Symbol => Object}] kwargs
95
- # Additional keywords arguments. These will be used to populate
96
- # {#options} and {#arguments}, along with `params`.
95
+ # Additional keywords arguments. These will be used to populate the
96
+ # command's `params`.
97
97
  #
98
98
  # @yield [command]
99
99
  # The newly initialized command.
@@ -115,8 +115,8 @@ module CommandMapper
115
115
  # The option and argument values.
116
116
  #
117
117
  # @param [Hash{Symbol => Object}] kwargs
118
- # Additional keywords arguments. These will be used to populate
119
- # {#options} and {#arguments}, along with `params`.
118
+ # Additional keywords arguments. These will be used to populate the
119
+ # command's `params`.
120
120
  #
121
121
  # @yield [command]
122
122
  # The newly initialized command.
@@ -144,8 +144,8 @@ module CommandMapper
144
144
  # The option and argument values.
145
145
  #
146
146
  # @param [Hash{Symbol => Object}] kwargs
147
- # Additional keywords arguments. These will be used to populate
148
- # {#options} and {#arguments}, along with `params`.
147
+ # Additional keywords arguments. These will be used to populate the
148
+ # command's `params`.
149
149
  #
150
150
  # @yield [command]
151
151
  # The newly initialized command.
@@ -170,8 +170,8 @@ module CommandMapper
170
170
  # The IO "mode" to open the IO pipe in.
171
171
  #
172
172
  # @param [Hash{Symbol => Object}] kwargs
173
- # Additional keywords arguments. These will be used to populate
174
- # {#options} and {#arguments}, along with `params`.
173
+ # Additional keywords arguments. These will be used to populate the
174
+ # command's `params`.
175
175
  #
176
176
  # @yield [command]
177
177
  # The newly initialized command.
@@ -191,6 +191,78 @@ module CommandMapper
191
191
  # @param [Hash{Symbol => Object}] params
192
192
  # The option and argument values.
193
193
  #
194
+ # @param [Hash{Symbol => Object}] sudo
195
+ # Additional `sudo` options.
196
+ #
197
+ # @option sudo [Boolean] :askpass
198
+ # Enables the `--askpass` `sudo` option.
199
+ #
200
+ # @option sudo [Boolean] :background
201
+ # Enables the `--background` `sudo` option
202
+ #
203
+ # @option sudo [Boolean] :bell
204
+ # Enables the `--bell` `sudo` option
205
+ #
206
+ # @option sudo [Integer] :close_from
207
+ # Enables the `--close-from=...` `sudo` option
208
+ #
209
+ # @option sudo [String] :chdir
210
+ # Enables the `--chdir=...` `sudo` option
211
+ #
212
+ # @option sudo [String] :preserve_env
213
+ # Enables the `--preseve-env=...` `sudo` option
214
+ #
215
+ # @option sudo [String, Boolean] :group
216
+ # Enables the `--preseve-env=...` `sudo` option
217
+ #
218
+ # @option sudo [Boolean] :set_home
219
+ # Enables the `--set-home` `sudo` option
220
+ #
221
+ # @option sudo [String] :host
222
+ # Enables the `--host=...` `sudo` option
223
+ #
224
+ # @option sudo [Boolean] :login
225
+ # Enables the `--login` `sudo` option
226
+ #
227
+ # @option sudo [Boolean] :remove_timestamp
228
+ # Enables the `--remove-timestamp` `sudo` option
229
+ #
230
+ # @option sudo [Boolean] :reset_timestamp
231
+ # Enables the `--reset-timestamp` `sudo` option
232
+ #
233
+ # @option sudo [Boolean] :non_interactive
234
+ # Enables the `--non-interactive` `sudo` option
235
+ #
236
+ # @option sudo [Boolean] :preserve_groups
237
+ # Enables the `--preserve-groups` `sudo` option
238
+ #
239
+ # @option sudo [String] :prompt
240
+ # Enables the `--prompt=...` `sudo` option
241
+ #
242
+ # @option sudo [String] :chroot
243
+ # Enables the `--chroot=...` `sudo` option
244
+ #
245
+ # @option sudo [String] :role
246
+ # Enables the `--role=...` `sudo` option
247
+ #
248
+ # @option sudo [Boolean] :stdin
249
+ # Enables the `--stdin` `sudo` option
250
+ #
251
+ # @option sudo [Boolean] :shell
252
+ # Enables the `--shell` `sudo` option
253
+ #
254
+ # @option sudo [String] :type
255
+ # Enables the `--type=...` `sudo` option
256
+ #
257
+ # @option sudo [Integer] :command_timeout
258
+ # Enables the `--command-timeout=...` `sudo` option
259
+ #
260
+ # @option sudo [String] :other_user
261
+ # Enables the `--other-user=...` `sudo` option
262
+ #
263
+ # @option sudo [String] :user
264
+ # Enables the `--user=...` `sudo` option
265
+ #
194
266
  # @param [Hash{Symbol => Object}] kwargs
195
267
  # Additional keyword arguments for {#initialize}.
196
268
  #
@@ -209,9 +281,6 @@ module CommandMapper
209
281
  #
210
282
  # Gets or sets the command name.
211
283
  #
212
- # @param [#to_s] new_name
213
- # The optional new command name.
214
- #
215
284
  # @return [String]
216
285
  # The command name.
217
286
  #
@@ -711,15 +780,127 @@ module CommandMapper
711
780
  #
712
781
  # Runs the command through `sudo`.
713
782
  #
714
- # @param [Hash{Symbol => Object}] sudo_params
715
- # Additional keyword arguments for {Sudo#initialize}.
783
+ # @param [Boolean] askpass
784
+ # Enables the `--askpass` `sudo` option.
785
+ #
786
+ # @param [Boolean] background
787
+ # Enables the `--background` `sudo` option
788
+ #
789
+ # @param [Boolean] bell
790
+ # Enables the `--bell` `sudo` option
791
+ #
792
+ # @param [Integer] close_from
793
+ # Enables the `--close-from=...` `sudo` option
794
+ #
795
+ # @param [String] chdir
796
+ # Enables the `--chdir=...` `sudo` option
797
+ #
798
+ # @param [String] preserve_env
799
+ # Enables the `--preseve-env=...` `sudo` option
800
+ #
801
+ # @param [String, Boolean] group
802
+ # Enables the `--preseve-env=...` `sudo` option
803
+ #
804
+ # @param [Boolean] set_home
805
+ # Enables the `--set-home` `sudo` option
806
+ #
807
+ # @param [String] host
808
+ # Enables the `--host=...` `sudo` option
809
+ #
810
+ # @param [Boolean] login
811
+ # Enables the `--login` `sudo` option
812
+ #
813
+ # @param [Boolean] remove_timestamp
814
+ # Enables the `--remove-timestamp` `sudo` option
815
+ #
816
+ # @param [Boolean] reset_timestamp
817
+ # Enables the `--reset-timestamp` `sudo` option
818
+ #
819
+ # @param [Boolean] non_interactive
820
+ # Enables the `--non-interactive` `sudo` option
821
+ #
822
+ # @param [Boolean] preserve_groups
823
+ # Enables the `--preserve-groups` `sudo` option
824
+ #
825
+ # @param [String] prompt
826
+ # Enables the `--prompt=...` `sudo` option
827
+ #
828
+ # @param [String] chroot
829
+ # Enables the `--chroot=...` `sudo` option
830
+ #
831
+ # @param [String] role
832
+ # Enables the `--role=...` `sudo` option
833
+ #
834
+ # @param [Boolean] stdin
835
+ # Enables the `--stdin` `sudo` option
836
+ #
837
+ # @param [Boolean] shell
838
+ # Enables the `--shell` `sudo` option
839
+ #
840
+ # @param [String] type
841
+ # Enables the `--type=...` `sudo` option
842
+ #
843
+ # @param [Integer] command_timeout
844
+ # Enables the `--command-timeout=...` `sudo` option
845
+ #
846
+ # @param [String] other_user
847
+ # Enables the `--other-user=...` `sudo` option
848
+ #
849
+ # @param [String] user
850
+ # Enables the `--user=...` `sudo` option
716
851
  #
717
852
  # @return [Boolean, nil]
718
853
  # Indicates whether the command exited successfully or not.
719
854
  # `nil` indicates the command could not be found.
720
855
  #
721
- def sudo_command(**sudo_kwargs,&block)
722
- sudo_params = sudo_kwargs.merge(command: command_argv)
856
+ def sudo_command(askpass: nil,
857
+ background: nil,
858
+ bell: nil,
859
+ close_from: nil,
860
+ chdir: nil,
861
+ preserve_env: nil,
862
+ group: nil,
863
+ set_home: nil,
864
+ host: nil,
865
+ login: nil,
866
+ remove_timestamp: nil,
867
+ reset_timestamp: nil,
868
+ non_interactive: nil,
869
+ preserve_groups: nil,
870
+ prompt: nil,
871
+ chroot: nil,
872
+ role: nil,
873
+ stdin: nil,
874
+ shell: nil,
875
+ type: nil,
876
+ command_timeout: nil,
877
+ other_user: nil,
878
+ user: nil, &block)
879
+ sudo_params = {command: command_argv}
880
+
881
+ sudo_params[:askpass] = askpass unless askpass.nil?
882
+ sudo_params[:background] = background unless background.nil?
883
+ sudo_params[:bell] = bell unless bell.nil?
884
+ sudo_params[:close_from] = close_from unless close_from.nil?
885
+ sudo_params[:chdir] = chdir unless chdir.nil?
886
+ sudo_params[:preserve_env] = preserve_env unless preserve_env.nil?
887
+ sudo_params[:group] = group unless group.nil?
888
+ sudo_params[:set_home] = set_home unless set_home.nil?
889
+ sudo_params[:host] = host unless host.nil?
890
+ sudo_params[:login] = login unless login.nil?
891
+ sudo_params[:remove_timestamp] = remove_timestamp unless remove_timestamp.nil?
892
+ sudo_params[:reset_timestamp] = reset_timestamp unless reset_timestamp.nil?
893
+ sudo_params[:non_interactive] = non_interactive unless non_interactive.nil?
894
+ sudo_params[:preserve_groups] = preserve_groups unless preserve_groups.nil?
895
+ sudo_params[:prompt] = prompt unless prompt.nil?
896
+ sudo_params[:chroot] = chroot unless chroot.nil?
897
+ sudo_params[:role] = role unless role.nil?
898
+ sudo_params[:stdin] = stdin unless stdin.nil?
899
+ sudo_params[:shell] = shell unless shell.nil?
900
+ sudo_params[:type] = type unless type.nil?
901
+ sudo_params[:command_timeout] = command_timeout unless command_timeout.nil?
902
+ sudo_params[:other_user] = other_user unless other_user.nil?
903
+ sudo_params[:user] = user unless user.nil?
723
904
 
724
905
  Sudo.run(sudo_params, command_env: @command_env, &block)
725
906
  end
@@ -1,5 +1,5 @@
1
- require 'command_mapper/exceptions'
2
- require 'command_mapper/option_value'
1
+ require_relative 'exceptions'
2
+ require_relative 'option_value'
3
3
 
4
4
  module CommandMapper
5
5
  #
@@ -1,4 +1,4 @@
1
- require 'command_mapper/arg'
1
+ require_relative 'arg'
2
2
 
3
3
  module CommandMapper
4
4
  #
@@ -1,5 +1,5 @@
1
- require 'command_mapper/command'
2
- require 'command_mapper/types/key_value_list'
1
+ require_relative 'command'
2
+ require_relative 'types/key_value_list'
3
3
 
4
4
  module CommandMapper
5
5
  #
@@ -7,7 +7,7 @@ module CommandMapper
7
7
  #
8
8
  # ## Sudo options:
9
9
  #
10
- # * `-A` - `sudo.ask_password`
10
+ # * `-A` - `sudo.askpass`
11
11
  # * `-b` - `sudo.background`
12
12
  # * `-C` - `sudo.close_from`
13
13
  # * `-E` - `sudo.preserve_env`
@@ -40,9 +40,9 @@ module CommandMapper
40
40
  option "--askpass"
41
41
  option "--background"
42
42
  option "--bell"
43
- option "--close-from", equals: true, value: true
44
- option "--chdir", equals: true, value: true
45
- option "--preserve-env", equals: true, value: true
43
+ option "--close-from", equals: true, value: {type: Num.new}
44
+ option "--chdir", equals: true, value: {type: InputDir.new}
45
+ option "--preserve-env", equals: true, value: {type: List.new, required: false}
46
46
  option "--edit"
47
47
  option "--group", equals: true, value: true
48
48
  option "--set-home"
@@ -55,12 +55,12 @@ module CommandMapper
55
55
  option "--non-interactive"
56
56
  option "--preserve-groups"
57
57
  option "--prompt", equals: true, value: true
58
- option "--chroot", equals: true, value: true
58
+ option "--chroot", equals: true, value: {type: InputDir.new}
59
59
  option "--role", equals: true, value: true
60
60
  option "--stdin"
61
61
  option "--shell"
62
62
  option "--type", equals: true, value: true
63
- option "--command-timeout", equals: true, value: true
63
+ option "--command-timeout", equals: true, value: {type: Num.new}
64
64
  option "--other-user", equals: true, value: true
65
65
  option "--user", equals: true, value: true
66
66
  option "--version"
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/type'
1
+ require_relative 'type'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/map'
1
+ require_relative 'map'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/num'
1
+ require_relative 'num'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/input_path'
1
+ require_relative 'input_path'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/input_path'
1
+ require_relative 'input_path'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/type'
1
+ require_relative 'type'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -1,5 +1,5 @@
1
- require 'command_mapper/types/type'
2
- require 'command_mapper/types/str'
1
+ require_relative 'type'
2
+ require_relative 'str'
3
3
 
4
4
  module CommandMapper
5
5
  module Types
@@ -41,9 +41,6 @@ module CommandMapper
41
41
  # @param [Type, Hash] value
42
42
  # The value's value type.
43
43
  #
44
- # @param [Hash{Symbol => Object}]
45
- # Additional keyword arguments for {Type#initialize}.
46
- #
47
44
  def initialize(separator: '=', key: Str.new, value: Str.new)
48
45
  @separator = separator
49
46
 
@@ -1,5 +1,5 @@
1
- require 'command_mapper/types/list'
2
- require 'command_mapper/types/key_value'
1
+ require_relative 'list'
2
+ require_relative 'key_value'
3
3
 
4
4
  module CommandMapper
5
5
  module Types
@@ -1,5 +1,5 @@
1
- require 'command_mapper/types/type'
2
- require 'command_mapper/types/str'
1
+ require_relative 'type'
2
+ require_relative 'str'
3
3
 
4
4
  module CommandMapper
5
5
  module Types
@@ -28,17 +28,19 @@ module CommandMapper
28
28
  # @param [String] separator
29
29
  # The list separator character.
30
30
  #
31
- # @param [Type, Hash] value
31
+ # @param [Type, Hash] type
32
32
  # The list's value type.
33
33
  #
34
+ # @param [Boolean] allow_empty
35
+ # Specifies whether the list type will accept empty values.
36
+ #
34
37
  def initialize(separator: ',', type: Str.new, allow_empty: false)
35
38
  if type.nil?
36
39
  raise(ArgumentError,"type: keyword cannot be nil")
37
40
  end
38
41
 
39
- @separator = separator
40
- @type = Types::Type(type)
41
-
42
+ @separator = separator
43
+ @type = Types::Type(type)
42
44
  @allow_empty = allow_empty
43
45
  end
44
46
 
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/type'
1
+ require_relative 'type'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/type'
1
+ require_relative 'type'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -1,4 +1,4 @@
1
- require 'command_mapper/types/type'
1
+ require_relative 'type'
2
2
 
3
3
  module CommandMapper
4
4
  module Types
@@ -57,7 +57,7 @@ module CommandMapper
57
57
  #
58
58
  # The default `validate` method for all types.
59
59
  #
60
- # @param [Object]
60
+ # @param [Object] value
61
61
  # The given value to validate.
62
62
  #
63
63
  # @return [true, (false, String)]
@@ -1,13 +1,13 @@
1
- require 'command_mapper/types/type'
2
- require 'command_mapper/types/str'
3
- require 'command_mapper/types/num'
4
- require 'command_mapper/types/dec'
5
- require 'command_mapper/types/hex'
6
- require 'command_mapper/types/map'
7
- require 'command_mapper/types/enum'
8
- require 'command_mapper/types/list'
9
- require 'command_mapper/types/key_value'
10
- require 'command_mapper/types/key_value_list'
11
- require 'command_mapper/types/input_path'
12
- require 'command_mapper/types/input_file'
13
- require 'command_mapper/types/input_dir'
1
+ require_relative 'types/type'
2
+ require_relative 'types/str'
3
+ require_relative 'types/num'
4
+ require_relative 'types/dec'
5
+ require_relative 'types/hex'
6
+ require_relative 'types/map'
7
+ require_relative 'types/enum'
8
+ require_relative 'types/list'
9
+ require_relative 'types/key_value'
10
+ require_relative 'types/key_value_list'
11
+ require_relative 'types/input_path'
12
+ require_relative 'types/input_file'
13
+ require_relative 'types/input_dir'
@@ -1,4 +1,4 @@
1
1
  module CommandMapper
2
2
  # Version of command_mapper
3
- VERSION = '0.3.1'
3
+ VERSION = '0.3.2'
4
4
  end
@@ -1,2 +1,2 @@
1
- require 'command_mapper/command'
2
- require 'command_mapper/version'
1
+ require_relative 'command_mapper/command'
2
+ require_relative 'command_mapper/version'
data/spec/commnad_spec.rb CHANGED
@@ -1416,7 +1416,7 @@ describe CommandMapper::Command do
1416
1416
  end
1417
1417
  end
1418
1418
 
1419
- describe "#sudo!" do
1419
+ describe "#sudo_command" do
1420
1420
  subject { command_class.new({opt1: opt1, arg1: arg1}, command_env: env) }
1421
1421
 
1422
1422
  let(:expected_argv) { [command_class.command, "--opt1", opt1, arg1] }
@@ -1426,6 +1426,43 @@ describe CommandMapper::Command do
1426
1426
 
1427
1427
  subject.sudo_command
1428
1428
  end
1429
+
1430
+ [
1431
+ :askpass,
1432
+ :background,
1433
+ :bell,
1434
+ :close_from,
1435
+ :chdir,
1436
+ :preserve_env,
1437
+ :group,
1438
+ :set_home,
1439
+ :host,
1440
+ :login,
1441
+ :remove_timestamp,
1442
+ :reset_timestamp,
1443
+ :non_interactive,
1444
+ :preserve_groups,
1445
+ :prompt,
1446
+ :chroot,
1447
+ :role,
1448
+ :stdin,
1449
+ :shell,
1450
+ :type,
1451
+ :command_timeout,
1452
+ :other_user,
1453
+ :user,
1454
+ ].each do |option|
1455
+ context "when given the #{option}: keyword argument" do
1456
+ let(:option) { option }
1457
+ let(:value) { true }
1458
+
1459
+ it "must pass the #{option}: keyword argument to CommandMapper::Sudo" do
1460
+ expect(Sudo).to receive(:run).with({option => value, :command => subject.command_argv}, :command_env => env)
1461
+
1462
+ subject.sudo_command(option => value)
1463
+ end
1464
+ end
1465
+ end
1429
1466
  end
1430
1467
 
1431
1468
  describe "#to_s" do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_mapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Postmodern
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-12-25 00:00:00.000000000 Z
11
+ date: 2024-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -99,7 +99,7 @@ metadata:
99
99
  documentation_uri: https://rubydoc.info/gems/command_mapper
100
100
  source_code_uri: https://github.com/postmodern/command_mapper.rb
101
101
  bug_tracker_uri: https://github.com/postmodern/command_mapper.rb/issues
102
- changelog_uri: https://github.com/postmodern/command_mapper.rb/blob/master/ChangeLog.md
102
+ changelog_uri: https://github.com/postmodern/command_mapper.rb/blob/main/ChangeLog.md
103
103
  rubygems_mfa_required: 'true'
104
104
  post_install_message:
105
105
  rdoc_options: []
@@ -116,7 +116,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
116
116
  - !ruby/object:Gem::Version
117
117
  version: '0'
118
118
  requirements: []
119
- rubygems_version: 3.3.26
119
+ rubygems_version: 3.4.10
120
120
  signing_key:
121
121
  specification_version: 4
122
122
  summary: Safe and secure execution of commands.