Method: CommandMapper::Command#sudo_command

Defined in:
lib/command_mapper/command.rb

#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.

[View source]

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