Class: GitPusshuTen::CLI
- Inherits:
-
Object
- Object
- GitPusshuTen::CLI
- Defined in:
- lib/gitpusshuten/cli.rb
Instance Attribute Summary collapse
-
#arguments ⇒ Object
Arguments.
-
#command ⇒ Object
Command.
-
#environment ⇒ Object
Environment.
Instance Method Summary collapse
-
#initialize(*args) ⇒ CLI
constructor
A new instance of CLI.
Constructor Details
#initialize(*args) ⇒ CLI
Returns a new instance of CLI.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 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 |
# File 'lib/gitpusshuten/cli.rb', line 16 def initialize(*args) ## # Clean up arguments @arguments = args.flatten.uniq.compact.map(&:strip) ## # If the arguments match the following pattern, it'll simply assign # the variables accordingly if @arguments.join(' ') =~ /(\w+\-?\w*) (.+) (for|to|from|on) (\w+)(.+)?/ @command = $1 @arguments = $2.split(' ') @environment = $4.to_sym ## # Allows for more arguments to be passed in after the regular expression. # These arguments will be converted to an array and appended to the "@arguments" array if $5.is_a?(String) @arguments += $5.split(' ') end return end ## # If the arguments match the following pattern, it'll assign the variables # and check check if the last argument in the array of @arguments is a # "for", "to", "from" or "on" string value, and deletes it if it is if @arguments.join(' ') =~ /(\w+\-?\w*) (.+) (\w+) environment/ @command = $1 @arguments = $2.split(' ') @environment = $3.to_sym ## # Clean up any for/to/from/on if it's the last argument # of the @arguments array since that'd be part of the CLI if %w[for to from on].include? @arguments.last @arguments.delete_at(@arguments.count - 1) end return end ## # If no arguments are specified it'll just take the command, # set the arguments to an empty array and set the environment if @arguments.join(' ') =~ /(\w+\-?\w*) (.+) (\w+)$/ @command = $1 @arguments = [] @environment = $2.to_sym return end ## # If only a command and one or more arguments are specified, # without an environment, the regular expression below is matched. if @arguments.join(' ') =~ /(\w+\-?\w*) (.+)$/ @command = $1 @arguments = $2.split(' ') return end end |
Instance Attribute Details
#arguments ⇒ Object
Arguments
6 7 8 |
# File 'lib/gitpusshuten/cli.rb', line 6 def arguments @arguments end |
#command ⇒ Object
Command
14 15 16 |
# File 'lib/gitpusshuten/cli.rb', line 14 def command @command end |
#environment ⇒ Object
Environment
10 11 12 |
# File 'lib/gitpusshuten/cli.rb', line 10 def environment @environment end |