Class: CommandMapper::Command

Inherits:
Object
  • Object
show all
Includes:
Types
Defined in:
lib/command_mapper/command.rb

Overview

Base class for all mapped commands.

Direct Known Subclasses

Sudo

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Types

Type

Constructor Details

#initialize(params = {}, command_name: self.class.command_name, command_path: nil, command_env: {}, **kwargs) {|self| ... } ⇒ Command

Initializes the command.

Examples:

with a symbol Hash

MyCommand.new({foo: 'bar', baz: 'qux'})

with a keyword arguments

MyCommand.new(foo: 'bar', baz: 'qux')

with a custom env Hash:

MyCommand.new({foo: 'bar', baz: 'qux'}, env: {'FOO' =>'bar'})
MyCommand.new(foo: 'bar', baz: 'qux', env: {'FOO' => 'bar'})

Parameters:

  • params (Hash{Symbol => Object}) (defaults to: {})

    The option and argument values.

  • command_name (String) (defaults to: self.class.command_name)

    Overrides the command with a custom command name.

  • command_path (String, nil) (defaults to: nil)

    Overrides the command with a custom path to the command.

  • command_env (Hash{String => String}) (defaults to: {})

    Custom environment variables to pass to the command.

  • kwargs (Hash{Symbol => Object})

    Additional keywords arguments. These will be used to populate the command's params.

Yields:

  • (self)

    The newly initialized command.

Yield Parameters:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/command_mapper/command.rb', line 71

def initialize(params={}, command_name: self.class.command_name,
                          command_path: nil,
                          command_env:  {},
                          **kwargs)
  @command_name = command_name
  @command_path = command_path
  @command_env  = command_env

  params = params.merge(kwargs)

  params.each do |name,value|
    self[name] = value
  end

  yield self if block_given?
end

Instance Attribute Details

#command_envHash{String => String} (readonly)

The environment variables to execute the command with.

Returns:

  • (Hash{String => String})


30
31
32
# File 'lib/command_mapper/command.rb', line 30

def command_env
  @command_env
end

#command_nameString (readonly)

The command name.

Returns:

  • (String)


20
21
22
# File 'lib/command_mapper/command.rb', line 20

def command_name
  @command_name
end

#command_pathString? (readonly)

The optional path to the command.

Returns:

  • (String, nil)


25
26
27
# File 'lib/command_mapper/command.rb', line 25

def command_path
  @command_path
end

#command_subcommandCommand? (readonly)

The subcommand's options and arguments.

Returns:



35
36
37
# File 'lib/command_mapper/command.rb', line 35

def command_subcommand
  @command_subcommand
end

Class Method Details

.argument(name, required: true, type: Str.new, repeats: false) ⇒ Object

Defines an option for the command.

Examples:

Define an argument:

argument :file

Define an argument that can be specified multiple times:

argument :files, repeats: true

Define an optional argument:

argument :file, required: false

Parameters:

  • name (Symbol)
  • required (Boolean) (defaults to: true)

    Specifies whether the argument is required or can be omitted.

  • type (Types::Type, Hash, nil) (defaults to: Str.new)

    The explicit type for the argument.

  • repeats (Boolean) (defaults to: false)

    Specifies whether the option can be repeated multiple times.

Raises:

  • (ArgumentError)

    The argument name conflicts with a pre-existing internal method, or another option or subcommand.



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
# File 'lib/command_mapper/command.rb', line 504

def self.argument(name, required: true, type: Str.new, repeats: false)
  name     = name.to_sym
  argument = Argument.new(name, required: required,
                                type:     type,
                                repeats:  repeats)

  if is_internal_method?(argument.name)
    raise(ArgumentError,"argument #{name.inspect} cannot override internal method with same name: ##{argument.name}")
  elsif has_option?(argument.name)
    raise(ArgumentError,"argument #{name.inspect} conflicts with another option with the same name")
  elsif has_subcommand?(argument.name)
    raise(ArgumentError,"argument #{name.inspect} conflicts with another subcommand with the same name")
  end

  self.arguments[argument.name] = argument
  attr_accessor name
end

.argumentsHash{Symbol => Argument}

All defined options.

Returns:

  • (Hash{Symbol => Argument})

    The mapping of argument names and Argument objects.



450
451
452
453
454
455
456
# File 'lib/command_mapper/command.rb', line 450

def self.arguments
  @arguments ||= if superclass < Command
                   superclass.arguments.dup
                 else
                   {}
                 end
end

.capture(params = {}, **kwargs) {|command| ... } ⇒ String

Initializes and runs the command in a shell and captures all stdout output.

Parameters:

  • params (Hash{Symbol => Object}) (defaults to: {})

    The option and argument values.

  • kwargs (Hash{Symbol => Object})

    Additional keywords arguments. These will be used to populate the command's params.

Yields:

  • (command)

    The newly initialized command.

Yield Parameters:

Returns:

  • (String)

    The stdout output of the command.



158
159
160
161
# File 'lib/command_mapper/command.rb', line 158

def self.capture(params={},**kwargs,&block)
  command = new(params,**kwargs,&block)
  command.capture_command
end

.command(new_command_name) {|self| ... } ⇒ Object

Examples:

command 'grep'
# ...
command 'grep' do
  option "--regexp", equals: true, value: true
  # ...
end

Parameters:

  • new_command_name (#to_s)

Yields:

  • (self)


317
318
319
320
# File 'lib/command_mapper/command.rb', line 317

def self.command(new_command_name,&block)
  @command_name = new_command_name.to_s.freeze
  yield self if block_given?
end

.command_nameString

Gets or sets the command name.

Returns:

  • (String)

    The command name.

Raises:

  • (NotImplementedError)

    The command class did not call command.



292
293
294
295
296
297
298
# File 'lib/command_mapper/command.rb', line 292

def self.command_name
  @command_name || if superclass < Command
                     superclass.command_name
                   else
                     raise(NotImplementedError,"#{self} did not call command(...)")
                   end
end

.has_argument?(name) ⇒ Boolean

Determines if an argument with the given name has been defined.

Parameters:

  • name (Symbol)

    The given name.

Returns:

  • (Boolean)

    Specifies whether an argument with the given name has been defined.

Since:

  • 0.2.0



471
472
473
# File 'lib/command_mapper/command.rb', line 471

def self.has_argument?(name)
  arguments.has_key?(name)
end

.has_option?(name) ⇒ Boolean

Determines if an option with the given name has been defined.

Parameters:

  • name (Symbol)

    The given name.

Returns:

  • (Boolean)

    Specifies whether an option with the given name has been defined.

Since:

  • 0.2.0



350
351
352
# File 'lib/command_mapper/command.rb', line 350

def self.has_option?(name)
  options.has_key?(name)
end

.has_subcommand?(name) ⇒ Boolean

Determines if a subcommand with the given name has been defined.

Parameters:

  • name (Symbol)

    The given name.

Returns:

  • (Boolean)

    Specifies whether a subcommand with the given name has been defined.

Since:

  • 0.2.0



551
552
553
# File 'lib/command_mapper/command.rb', line 551

def self.has_subcommand?(name)
  subcommands.has_key?(name)
end

.option(flag, name: nil, value: nil, repeats: false, equals: nil, value_in_flag: nil, &block) ⇒ Object

Defines an option for the command.

Examples:

Defining an option:

option '--foo'

Defining an option with a custom name:

option '-F', name: :foo

Defining an option who's value is required:

option '--file', value: true

Defining an option who's value is optional:

option '--file', value: {required: false}

Defining an -Fvalue option:

option '--foo', value: true, value_in_flag: true

Defining an --opt=value option:

option '--foo', equals: true, value: true

Defining an option that can be repeated multiple times:

option '--foo', repeats: true

Defining an option that takes a comma-separated list:

option '--list', value: List.new

Parameters:

  • flag (String)

    The option's command-line flag.

  • name (Symbol, nil) (defaults to: nil)

    The option's name.

  • value (Hash, nil) (defaults to: nil)

    The option's value.

  • repeats (Boolean) (defaults to: false)

    Specifies whether the option can be given multiple times.

  • equals (Boolean) (defaults to: nil)

    Specifies whether the option's flag and value should be separated with a = character.

  • value_in_flag (Boolean) (defaults to: nil)

    Specifies that the value should be appended to the option's flag (ex: -Fvalue).

Options Hash (value:):

  • :required (Boolean)

    Specifies whether the option requires a value or not.

  • :type (Types:Type, Hash, nil)

    The explicit type for the option's value.

Raises:

  • (ArgumentError)

    The option flag conflicts with a pre-existing internal method, or another argument or subcommand.



413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
# File 'lib/command_mapper/command.rb', line 413

def self.option(flag, name: nil, value: nil, repeats: false,
                      # formatting options
                      equals:        nil,
                      value_in_flag: nil,
                      &block)
  option = Option.new(flag, name:    name,
                            value:   value,
                            repeats: repeats,
                            # formatting options
                            equals:        equals,
                            value_in_flag: value_in_flag,
                            &block)

  if is_internal_method?(option.name)
    if name
      raise(ArgumentError,"option #{flag.inspect} with name #{name.inspect} cannot override the internal method with same name: ##{option.name}")
    else
      raise(ArgumentError,"option #{flag.inspect} maps to method name ##{option.name} and cannot override the internal method with same name: ##{option.name}")
    end
  elsif has_argument?(option.name)
    raise(ArgumentError,"option #{flag.inspect} with name #{option.name.inspect} conflicts with another argument with the same name")
  elsif has_subcommand?(option.name)
    raise(ArgumentError,"option #{flag.inspect} with name #{option.name.inspect} conflicts with another subcommand with the same name")
  end

  self.options[option.name] = option
  attr_accessor option.name
end

.optionsHash{Symbol => Option}

All defined options.

Returns:



329
330
331
332
333
334
335
# File 'lib/command_mapper/command.rb', line 329

def self.options
  @options ||= if superclass < Command
                 superclass.options.dup
               else
                 {}
               end
end

.popen(params = {}, mode: 'r', **kwargs) {|command| ... } ⇒ IO

Initializes and executes the command and returns an IO object to it.

Parameters:

  • params (Hash{Symbol => Object}) (defaults to: {})

    The option and argument values.

  • mode (String) (defaults to: 'r')

    The IO "mode" to open the IO pipe in.

  • kwargs (Hash{Symbol => Object})

    Additional keywords arguments. These will be used to populate the command's params.

Yields:

  • (command)

    The newly initialized command.

Yield Parameters:

Returns:

  • (IO)


183
184
185
186
# File 'lib/command_mapper/command.rb', line 183

def self.popen(params={}, mode: 'r', **kwargs,&block)
  command = new(params,**kwargs,&block)
  command.popen_command
end

.run(params = {}, **kwargs) {|command| ... } ⇒ Boolean?

Initializes and runs the command.

Parameters:

  • params (Hash{Symbol => Object}) (defaults to: {})

    The option and argument values.

  • kwargs (Hash{Symbol => Object})

    Additional keywords arguments. These will be used to populate the command's params.

Yields:

  • (command)

    The newly initialized command.

Yield Parameters:

Returns:

  • (Boolean, nil)


105
106
107
108
# File 'lib/command_mapper/command.rb', line 105

def self.run(params={},**kwargs,&block)
  command = new(params,**kwargs,&block)
  command.run_command
end

.spawn(params = {}, **kwargs) {|command| ... } ⇒ Integer

Initializes and spawns the command as a separate process, returning the PID of the process.

Parameters:

  • params (Hash{Symbol => Object}) (defaults to: {})

    The option and argument values.

  • kwargs (Hash{Symbol => Object})

    Additional keywords arguments. These will be used to populate the command's params.

Yields:

  • (command)

    The newly initialized command.

Yield Parameters:

Returns:

  • (Integer)

    The PID of the new command process.

Raises:

  • (Errno::ENOENT)

    The command could not be found.

Since:

  • 0.2.0



134
135
136
137
# File 'lib/command_mapper/command.rb', line 134

def self.spawn(params={},**kwargs,&block)
  command = new(params,**kwargs,&block)
  command.spawn_command
end

.subcommand(name) {|subcommand| ... } ⇒ Object

Note:

Also defines a class within the command class using the subcommand's name.

Defines a subcommand.

Examples:

Defining a sub-command:

class Git
  command 'git' do
    subcommand 'clone' do
      option '--bare'
      # ...
    end
  end
end

Parameters:

  • name (String)

    The name of the subcommand.

Yields:

  • (subcommand)

    The given block will be used to populate the subcommand's options.

Yield Parameters:

  • subcommand (Command)

    The newly created subcommand class.

Raises:

  • (ArgumentError)

    The subcommand name conflicts with a pre-existing internal method, or another option or argument.



585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
# File 'lib/command_mapper/command.rb', line 585

def self.subcommand(name,&block)
  name            = name.to_s
  method_name     = name.tr('-','_')
  class_name      = name.split(/[_-]+/).map(&:capitalize).join
  subcommand_name = method_name.to_sym

  if is_internal_method?(method_name)
    raise(ArgumentError,"subcommand #{name.inspect} maps to method name ##{method_name} and cannot override the internal method with same name: ##{method_name}")
  elsif has_option?(subcommand_name)
    raise(ArgumentError,"subcommand #{name.inspect} conflicts with another option with the same name")
  elsif has_argument?(subcommand_name)
    raise(ArgumentError,"subcommand #{name.inspect} conflicts with another argument with the same name")
  end

  subcommand_class = Class.new(Command)
  subcommand_class.command(name)
  subcommand_class.class_eval(&block)

  self.subcommands[subcommand_name] = subcommand_class
  const_set(class_name,subcommand_class)

  define_method(method_name) do |&block|
    if block then @command_subcommand = subcommand_class.new(&block)
    else          @command_subcommand
    end
  end

  define_method(:"#{method_name}=") do |options|
    @command_subcommand = if options
                            subcommand_class.new(options)
                          end
  end
end

.subcommandsHash{Symbol => Command.class}

All defined subcommands.

Returns:

  • (Hash{Symbol => Command.class})

    The mapping of subcommand names and subcommand classes.



530
531
532
533
534
535
536
# File 'lib/command_mapper/command.rb', line 530

def self.subcommands
  @subcommands ||= if superclass < Command
                     superclass.subcommands.dup
                   else
                     {}
                   end
end

.sudo(params = {}, sudo: {}, **kwargs) {|command| ... } ⇒ Boolean?

Initializes and runs the command through sudo.

Parameters:

  • params (Hash{Symbol => Object}) (defaults to: {})

    The option and argument values.

  • sudo (Hash{Symbol => Object}) (defaults to: {})

    Additional sudo options.

  • kwargs (Hash{Symbol => Object})

    Additional keyword arguments for #initialize.

Options Hash (sudo:):

  • :askpass (Boolean)

    Enables the --askpass sudo option.

  • :background (Boolean)

    Enables the --background sudo option

  • :bell (Boolean)

    Enables the --bell sudo option

  • :close_from (Integer)

    Enables the --close-from=... sudo option

  • :chdir (String)

    Enables the --chdir=... sudo option

  • :preserve_env (String)

    Enables the --preseve-env=... sudo option

  • :group (String, Boolean)

    Enables the --preseve-env=... sudo option

  • :set_home (Boolean)

    Enables the --set-home sudo option

  • :host (String)

    Enables the --host=... sudo option

  • :login (Boolean)

    Enables the --login sudo option

  • :remove_timestamp (Boolean)

    Enables the --remove-timestamp sudo option

  • :reset_timestamp (Boolean)

    Enables the --reset-timestamp sudo option

  • :non_interactive (Boolean)

    Enables the --non-interactive sudo option

  • :preserve_groups (Boolean)

    Enables the --preserve-groups sudo option

  • :prompt (String)

    Enables the --prompt=... sudo option

  • :chroot (String)

    Enables the --chroot=... sudo option

  • :role (String)

    Enables the --role=... sudo option

  • :stdin (Boolean)

    Enables the --stdin sudo option

  • :shell (Boolean)

    Enables the --shell sudo option

  • :type (String)

    Enables the --type=... sudo option

  • :command_timeout (Integer)

    Enables the --command-timeout=... sudo option

  • :other_user (String)

    Enables the --other-user=... sudo option

  • :user (String)

    Enables the --user=... sudo option

Yields:

  • (command)

    The newly initialized command.

Yield Parameters:

Returns:

  • (Boolean, nil)


276
277
278
279
# File 'lib/command_mapper/command.rb', line 276

def self.sudo(params={}, sudo: {}, **kwargs,&block)
  command = new(params,**kwargs,&block)
  command.sudo_command(**sudo)
end

Instance Method Details

#[](name) ⇒ Object

Gets the value of an option or an argument.

Parameters:

  • name (Symbol)

    The name of the option, argument, or subcommand.

Returns:

  • (Object)

    The value of the option, argument, or subcommand.

Raises:

  • (ArgumentError)

    The given name was not match any option or argument.



631
632
633
634
635
636
637
638
639
# File 'lib/command_mapper/command.rb', line 631

def [](name)
  name = name.to_s

  if respond_to?(name)
    send(name)
  else
    raise(ArgumentError,"#{self.class} does not define ##{name}")
  end
end

#[]=(name, value) ⇒ Object

Sets an option or an argument with the given name.

Parameters:

  • name (Symbol)

    The name of the option, argument, or subcommand.

  • value (Object)

    The new value for the option, argument, or subcommand.

Returns:

  • (Object)

    The new value for the option, argument, or subcommand.

Raises:

  • (ArgumentError)

    The given name was not match any option or argument.



656
657
658
659
660
661
662
# File 'lib/command_mapper/command.rb', line 656

def []=(name,value)
  if respond_to?("#{name}=")
    send("#{name}=",value)
  else
    raise(ArgumentError,"#{self.class} does not define ##{name}=")
  end
end

#capture_commandString

Runs the command in a shell and captures all stdout output.

Returns:

  • (String)

    The stdout output of the command.



764
765
766
# File 'lib/command_mapper/command.rb', line 764

def capture_command
  `#{command_string}`
end

#command_argvArray<String>

Returns an Array of command-line arguments for the command.

Returns:

  • (Array<String>)

    The formatted command-line arguments.

Raises:

  • (ArgumentReqired)

    A required argument was not set.



673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
# File 'lib/command_mapper/command.rb', line 673

def command_argv
  argv = [@command_path || @command_name]

  self.class.options.each do |name,option|
    unless (value = self[name]).nil?
      option.argv(argv,value)
    end
  end

  if @command_subcommand
    # a subcommand takes precedence over any command arguments
    argv.concat(@command_subcommand.command_argv)
  else
    additional_args = []

    self.class.arguments.each do |name,argument|
      value = self[name]

      if value.nil?
        if argument.required?
          raise(ArgumentRequired,"argument #{name} is required")
        end
      else
        argument.argv(additional_args,value)
      end
    end

    if additional_args.any? { |arg| arg.start_with?('-') }
      # append a '--' separator if any of the arguments start with a '-'
      argv << '--'
    end

    argv.concat(additional_args)
  end

  return argv
end

#command_stringString

Escapes any shell control-characters so that it can be ran in a shell.

Returns:

  • (String)

    The shell-escaped command.



717
718
719
720
721
722
723
724
725
726
727
728
729
# File 'lib/command_mapper/command.rb', line 717

def command_string
  escaped_command = Shellwords.shelljoin(command_argv)

  unless @command_env.empty?
    escaped_env = @command_env.map { |name,value|
      "#{Shellwords.shellescape(name)}=#{Shellwords.shellescape(value)}"
    }.join(' ')

    escaped_command = "#{escaped_env} #{escaped_command}"
  end

  return escaped_command
end

#popen_command(mode = nil) ⇒ IO

Executes the command and returns an IO object to it.

Returns:

  • (IO)

    The IO object for the command's STDIN.



774
775
776
777
778
# File 'lib/command_mapper/command.rb', line 774

def popen_command(mode=nil)
  if mode then IO.popen(@command_env,command_argv,mode)
  else         IO.popen(@command_env,command_argv)
  end
end

#run_commandBoolean?

Runs the command.

Returns:

  • (Boolean, nil)

    Indicates whether the command exited successfully or not. nil indicates the command could not be found.



738
739
740
# File 'lib/command_mapper/command.rb', line 738

def run_command
  Kernel.system(@command_env,*command_argv)
end

#spawn_commandInteger

Spawns the command as a separate process, returning the PID of the process.

Returns:

  • (Integer)

    The PID of the new command process.

Raises:

  • (Errno::ENOENT)

    The command could not be found.

Since:

  • 0.2.0



754
755
756
# File 'lib/command_mapper/command.rb', line 754

def spawn_command
  Process.spawn(@command_env,*command_argv)
end

#sudo_command(askpass: nil, background: nil, bell: nil, close_from: nil, chdir: nil, preserve_env: nil, group: nil, set_home: nil, host: nil, login: nil, remove_timestamp: nil, reset_timestamp: nil, non_interactive: nil, preserve_groups: nil, prompt: nil, chroot: nil, role: nil, stdin: nil, shell: nil, type: nil, command_timeout: nil, other_user: nil, user: nil, &block) ⇒ Boolean?

Runs the command through sudo.

Parameters:

  • askpass (Boolean) (defaults to: nil)

    Enables the --askpass sudo option.

  • background (Boolean) (defaults to: nil)

    Enables the --background sudo option

  • bell (Boolean) (defaults to: nil)

    Enables the --bell sudo option

  • close_from (Integer) (defaults to: nil)

    Enables the --close-from=... sudo option

  • chdir (String) (defaults to: nil)

    Enables the --chdir=... sudo option

  • preserve_env (String) (defaults to: nil)

    Enables the --preseve-env=... sudo option

  • group (String, Boolean) (defaults to: nil)

    Enables the --preseve-env=... sudo option

  • set_home (Boolean) (defaults to: nil)

    Enables the --set-home sudo option

  • host (String) (defaults to: nil)

    Enables the --host=... sudo option

  • login (Boolean) (defaults to: nil)

    Enables the --login sudo option

  • remove_timestamp (Boolean) (defaults to: nil)

    Enables the --remove-timestamp sudo option

  • reset_timestamp (Boolean) (defaults to: nil)

    Enables the --reset-timestamp sudo option

  • non_interactive (Boolean) (defaults to: nil)

    Enables the --non-interactive sudo option

  • preserve_groups (Boolean) (defaults to: nil)

    Enables the --preserve-groups sudo option

  • prompt (String) (defaults to: nil)

    Enables the --prompt=... sudo option

  • chroot (String) (defaults to: nil)

    Enables the --chroot=... sudo option

  • role (String) (defaults to: nil)

    Enables the --role=... sudo option

  • stdin (Boolean) (defaults to: nil)

    Enables the --stdin sudo option

  • shell (Boolean) (defaults to: nil)

    Enables the --shell sudo option

  • type (String) (defaults to: nil)

    Enables the --type=... sudo option

  • command_timeout (Integer) (defaults to: nil)

    Enables the --command-timeout=... sudo option

  • other_user (String) (defaults to: nil)

    Enables the --other-user=... sudo option

  • user (String) (defaults to: nil)

    Enables the --user=... sudo option

Returns:

  • (Boolean, nil)

    Indicates whether the command exited successfully or not. nil indicates the command could not be found.



856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
# File 'lib/command_mapper/command.rb', line 856

def sudo_command(askpass: nil,
                 background: nil,
                 bell: nil,
                 close_from: nil,
                 chdir: nil,
                 preserve_env: nil,
                 group: nil,
                 set_home: nil,
                 host: nil,
                 login: nil,
                 remove_timestamp: nil,
                 reset_timestamp: nil,
                 non_interactive: nil,
                 preserve_groups: nil,
                 prompt: nil,
                 chroot: nil,
                 role: nil,
                 stdin: nil,
                 shell: nil,
                 type: nil,
                 command_timeout: nil,
                 other_user: nil,
                 user: nil, &block)
  sudo_params = {command: command_argv}

  sudo_params[:askpass]          = askpass          unless askpass.nil?
  sudo_params[:background]       = background       unless background.nil?
  sudo_params[:bell]             = bell             unless bell.nil?
  sudo_params[:close_from]       = close_from       unless close_from.nil?
  sudo_params[:chdir]            = chdir            unless chdir.nil?
  sudo_params[:preserve_env]     = preserve_env     unless preserve_env.nil?
  sudo_params[:group]            = group            unless group.nil?
  sudo_params[:set_home]         = set_home         unless set_home.nil?
  sudo_params[:host]             = host             unless host.nil?
  sudo_params[:login]            =             unless .nil?
  sudo_params[:remove_timestamp] = remove_timestamp unless remove_timestamp.nil?
  sudo_params[:reset_timestamp]  = reset_timestamp  unless reset_timestamp.nil?
  sudo_params[:non_interactive]  = non_interactive  unless non_interactive.nil?
  sudo_params[:preserve_groups]  = preserve_groups  unless preserve_groups.nil?
  sudo_params[:prompt]           = prompt           unless prompt.nil?
  sudo_params[:chroot]           = chroot           unless chroot.nil?
  sudo_params[:role]             = role             unless role.nil?
  sudo_params[:stdin]            = stdin            unless stdin.nil?
  sudo_params[:shell]            = shell            unless shell.nil?
  sudo_params[:type]             = type             unless type.nil?
  sudo_params[:command_timeout]  = command_timeout  unless command_timeout.nil?
  sudo_params[:other_user]       = other_user       unless other_user.nil?
  sudo_params[:user]             = user             unless user.nil?

  Sudo.run(sudo_params, command_env: @command_env, &block)
end

#to_aObject

See Also:

  • #argv


911
912
913
# File 'lib/command_mapper/command.rb', line 911

def to_a
  command_argv
end

#to_sObject

See Also:

  • #shellescape


918
919
920
# File 'lib/command_mapper/command.rb', line 918

def to_s
  command_string
end