Class: Codestrap::Cli
- Inherits:
-
Object
- Object
- Codestrap::Cli
- Defined in:
- lib/codestrap/cli.rb
Defined Under Namespace
Classes: CodestrapPathError
Instance Attribute Summary collapse
-
#argv ⇒ String
Same as ARGV.
-
#command ⇒ String
Calling command.
Instance Method Summary collapse
-
#abspath(path = nil) ⇒ String
Absolute path of calling command.
-
#initialize(argv) ⇒ Cli
constructor
A new instance of Cli.
- #options ⇒ Object
Constructor Details
#initialize(argv) ⇒ Cli
Returns a new instance of Cli.
43 44 45 46 47 |
# File 'lib/codestrap/cli.rb', line 43 def initialize argv self.abspath(argv.shift) @command = File.basename self.abspath @argv = argv end |
Instance Attribute Details
#argv ⇒ String
Same as ARGV
14 15 16 |
# File 'lib/codestrap/cli.rb', line 14 def argv @argv end |
#command ⇒ String
Calling command
9 10 11 |
# File 'lib/codestrap/cli.rb', line 9 def command @command end |
Instance Method Details
#abspath(path = nil) ⇒ String
Absolute path of calling command
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/codestrap/cli.rb', line 22 def abspath path=nil return @abspath if @abspath and not path if path =~ /\// p = File.(path) @abspath = p if File.exist? p else ENV['PATH'].split(File::PATH_SEPARATOR).each do |d| p = File.join(d, path) next unless d.length > 0 next unless File.exist? p @abspath = File.(p) break end end if @abspath @abspath else raise CodestrapPathError, "Could not find #{path}" end end |
#options ⇒ Object
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 |
# File 'lib/codestrap/cli.rb', line 49 def ||= ( = OpenStruct.new .generate = false OptionParser.new do |opts| opts. = "Usage: #{self.command} [-?|-h|--help]" opts.separator '' opts.separator 'Specific options:' opts.on('--version', 'Show version') do puts Codestrap::VERSION exit 0 end opts.on('-?', '-h', '--help', 'Show this message') do puts opts exit 0 end opts.on('-g', '--generate', 'Generate links') do .generate = true end end.parse!(self.argv) ) end |