Class: Snaptoken::CLI
- Inherits:
-
Object
- Object
- Snaptoken::CLI
- Defined in:
- lib/snaptoken/cli.rb
Constant Summary collapse
- CONFIG_FILE =
"leg.yml"
Instance Method Summary collapse
-
#initialize ⇒ CLI
constructor
A new instance of CLI.
- #run(args) ⇒ Object
Constructor Details
#initialize ⇒ CLI
Returns a new instance of CLI.
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 |
# File 'lib/snaptoken/cli.rb', line 4 def initialize initial_dir = FileUtils.pwd last_dir = nil last_dir2 = nil while FileUtils.pwd != last_dir if File.exist?(CONFIG_FILE) @config = YAML.load(File.read(CONFIG_FILE)) unless @config.is_a? Hash puts "Error: Invalid config file." exit! end @config[:path] = FileUtils.pwd @config[:step_path] = last_dir2 @config[:orig_path] = initial_dir break end last_dir2 = last_dir last_dir = FileUtils.pwd FileUtils.cd('..') end FileUtils.cd(initial_dir) end |
Instance Method Details
#run(args) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/snaptoken/cli.rb', line 30 def run(args) args = ["help"] if args.empty? cmd_name = args.shift.downcase if cmd_name =~ /\A\d+\z/ args.unshift(cmd_name) cmd_name = "ref" end if cmd = Snaptoken::Commands::LIST.find { |cmd| cmd.name == cmd_name } cmd.new(args, @config).run else puts "There is no '#{cmd_name}' command. Run `leg help` for help." end end |