Class: Dandelion::CLI
- Inherits:
-
Object
- Object
- Dandelion::CLI
- Defined in:
- lib/dandelion/cli.rb
Instance Method Summary collapse
- #adapter ⇒ Object
- #command_class ⇒ Object
- #config ⇒ Object
- #execute! ⇒ Object
-
#initialize(args) ⇒ CLI
constructor
A new instance of CLI.
- #repo ⇒ Object
- #workspace ⇒ Object
Constructor Details
Instance Method Details
#adapter ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/dandelion/cli.rb', line 20 def adapter @adapter ||= Adapter::Base.create_adapter(config[:adapter], config) rescue Adapter::InvalidAdapterError => e log.fatal("Unsupported adapter: #{config[:adapter]}") exit 1 rescue Adapter::MissingDependencyError => e log.fatal("The #{config[:adapter]} adapter requires additional gems:") log.fatal(e.gems.map { |name| " #{name}"}.join("\n")) log.fatal("Please install the gems first: gem install #{e.gems.join(' ')}") exit 1 end |
#command_class ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/dandelion/cli.rb', line 40 def command_class @command_class ||= Command::Base.lookup(@args.shift.to_sym) rescue Command::InvalidCommandError => e log.fatal("Invalid command: #{e}") display_help exit 1 end |
#config ⇒ Object
14 15 16 17 18 |
# File 'lib/dandelion/cli.rb', line 14 def config @config ||= Config.new(path: config_path).tap do |config| config[:adapter] ||= config[:scheme] # backward compat end end |
#execute! ⇒ Object
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 |
# File 'lib/dandelion/cli.rb', line 48 def execute! if @args.length == 0 @options[:help] = true end parse!(@parser) if @options[:version] log.info("Dandelion #{Dandelion::VERSION}") exit end if @options[:help] display_help exit end parse!(command_class.parser(@options)) validate! command = command_class.new(workspace, config, @options) command.setup(@args) begin command.execute! rescue RevisionError => e log.fatal("Invalid revision: #{e}") exit 1 end end |
#repo ⇒ Object
32 33 34 |
# File 'lib/dandelion/cli.rb', line 32 def repo @repo ||= Rugged::Repository.new(repo_path) end |