Class: Docker::Cli::Command
- Inherits:
-
Object
- Object
- Docker::Cli::Command
- Includes:
- TR::CondUtils, TR::TerminalUtils
- Defined in:
- lib/docker/cli/command.rb
Defined Under Namespace
Classes: CommandError
Instance Attribute Summary collapse
-
#command_buffer ⇒ Object
Returns the value of attribute command_buffer.
Instance Method Summary collapse
-
#initialize(cmd, required_interaction = false) ⇒ Command
constructor
A new instance of Command.
- #interactive_session? ⇒ Boolean
- #run(&block) ⇒ Object
- #to_string ⇒ Object
Constructor Details
#initialize(cmd, required_interaction = false) ⇒ Command
Returns a new instance of Command.
19 20 21 22 23 24 |
# File 'lib/docker/cli/command.rb', line 19 def initialize(cmd, required_interaction = false) @command_buffer = cmd @runner = TTY::Command.new @required_interaction = required_interaction @required_interaction = false if not_bool?(@required_interaction) end |
Instance Attribute Details
#command_buffer ⇒ Object
Returns the value of attribute command_buffer.
18 19 20 |
# File 'lib/docker/cli/command.rb', line 18 def command_buffer @command_buffer end |
Instance Method Details
#interactive_session? ⇒ Boolean
26 27 28 |
# File 'lib/docker/cli/command.rb', line 26 def interactive_session? @required_interaction end |
#run(&block) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/docker/cli/command.rb', line 30 def run(&block) if interactive_session? pmt = TTY::Prompt.new terminal = pmt.select "Command is an interactive command. New terminal session is required. Please select one of the session below to proceed:" do |m| detect_terminal.each do |t| m.choice t, t end m.choice "Quit", :quit end if terminal != :quit tu_new_terminal(terminal, @command_buffer) #case terminal #when "terminator" # `#{terminal} -x "#{@command_buffer.join(" ")}"` #when "gnome-terminal" # `#{terminal} -- bash -c "#{@command_buffer.join(" ")}; exec bash"` #when "iTerm2" # `osascript -e \ # 'tell application "iTerm" # activate # create window with default profile # delay 0.5 # set currentWindow to current window # tell current session of currentWindow # write text "#{@command_buffer.join(" ")}" # end tell # end tell' # ` #when "Terminal" # `osascript -e \ # 'tell application "Terminal" # activate # do script "#{@command_buffer.join(" ")}" # end tell' # ` #else # raise Error, "Unfinished supporting terminal : #{terminal}" #end pmt.puts "\n Prompt running inside the Docker shall be opened in a new window\n\n" end else @outStream = [] @errStream = [] result = @runner.run!(@command_buffer.join(" ")) do |out, err| if block block.call(:outstream, out) block.call(:errstream, err) else @outStream << out if not_empty?(out) @errStream << err if not_empty?(err) end end CommandResult.new(result, @outStream, @errStream) #{ outStream: @outStream, errStream: @errStream, result: @result } end end |
#to_string ⇒ Object
100 101 102 |
# File 'lib/docker/cli/command.rb', line 100 def to_string @command_buffer end |