Class: Kward::NativeShell::Invocation
- Inherits:
-
Struct
- Object
- Struct
- Kward::NativeShell::Invocation
- Defined in:
- lib/kward/shell/native_invocation.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Returns the value of attribute arguments.
-
#command ⇒ Object
Returns the value of attribute command.
-
#command_name ⇒ Object
Returns the value of attribute command_name.
-
#file ⇒ Object
Returns the value of attribute file.
-
#help ⇒ Object
Returns the value of attribute help.
-
#interactive ⇒ Object
Returns the value of attribute interactive.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#arguments ⇒ Object
Returns the value of attribute arguments
3 4 5 |
# File 'lib/kward/shell/native_invocation.rb', line 3 def arguments @arguments end |
#command ⇒ Object
Returns the value of attribute command
3 4 5 |
# File 'lib/kward/shell/native_invocation.rb', line 3 def command @command end |
#command_name ⇒ Object
Returns the value of attribute command_name
3 4 5 |
# File 'lib/kward/shell/native_invocation.rb', line 3 def command_name @command_name end |
#file ⇒ Object
Returns the value of attribute file
3 4 5 |
# File 'lib/kward/shell/native_invocation.rb', line 3 def file @file end |
#help ⇒ Object
Returns the value of attribute help
3 4 5 |
# File 'lib/kward/shell/native_invocation.rb', line 3 def help @help end |
#interactive ⇒ Object
Returns the value of attribute interactive
3 4 5 |
# File 'lib/kward/shell/native_invocation.rb', line 3 def interactive @interactive end |
#options ⇒ Object
Returns the value of attribute options
3 4 5 |
# File 'lib/kward/shell/native_invocation.rb', line 3 def @options end |
Class Method Details
.parse(arguments) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/kward/shell/native_invocation.rb', line 4 def self.parse(arguments) args = arguments.dup = [] mode = nil interactive = false while args.first&.start_with?("-", "+") && args.first != "-" option = args.shift break if option == "--" if option == "--help" return new(help: true) end option[1..].each_char do |flag| case flag when "c", "s" raise ArgumentError, "-c and -s are mutually exclusive" if mode && mode != flag raise ArgumentError, "+#{flag} is not supported" if option.start_with?("+") mode = flag when "i" then interactive = option.start_with?("-") when "o" raise ArgumentError, "#{option} requires an option name" if args.empty? .concat(["#{option[0]}o", args.shift]) else << "#{option[0]}#{flag}" end end end args.shift if args.first == "-" command = args.shift if mode == "c" raise ArgumentError, "-c requires a command" if mode == "c" && !command file = args.shift unless mode || args.empty? command_name = args.shift if mode == "c" new(options: , arguments: args, file: file, command: command, command_name: command_name, interactive: interactive) end |
Instance Method Details
#prompt?(input, error) ⇒ Boolean
37 38 39 |
# File 'lib/kward/shell/native_invocation.rb', line 37 def prompt?(input, error) !help && !command && !file && input.tty? && error.tty? end |