Class: Ghost::Cli
- Inherits:
-
Object
- Object
- Ghost::Cli
- Defined in:
- lib/ghost/cli.rb,
lib/ghost/cli/task.rb
Defined Under Namespace
Classes: Task
Instance Attribute Summary collapse
-
#out ⇒ Object
Returns the value of attribute out.
-
#parser ⇒ Object
Returns the value of attribute parser.
-
#store ⇒ Object
Returns the value of attribute store.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(out = STDOUT) ⇒ Cli
constructor
A new instance of Cli.
- #parse(args = ARGV) ⇒ Object
- #tasks ⇒ Object
Constructor Details
#initialize(out = STDOUT) ⇒ Cli
Returns a new instance of Cli.
11 12 13 14 15 16 |
# File 'lib/ghost/cli.rb', line 11 def initialize(out = STDOUT) self.store = Ghost::Store::HostsFileStore.new(section_name: 'ghost') self.out = out setup_parser end |
Instance Attribute Details
#out ⇒ Object
Returns the value of attribute out.
9 10 11 |
# File 'lib/ghost/cli.rb', line 9 def out @out end |
#parser ⇒ Object
Returns the value of attribute parser.
9 10 11 |
# File 'lib/ghost/cli.rb', line 9 def parser @parser end |
#store ⇒ Object
Returns the value of attribute store.
9 10 11 |
# File 'lib/ghost/cli.rb', line 9 def store @store end |
Class Method Details
.task(*names, &block) ⇒ Object
59 60 61 62 63 64 |
# File 'lib/ghost/cli/task.rb', line 59 def task(*names, &block) task = Class.new(Task, &block) names.map!(&:to_s) task.name = names.first names.each { |name| tasks[name] = task } end |
.tasks ⇒ Object
66 67 68 |
# File 'lib/ghost/cli/task.rb', line 66 def tasks @tasks ||= {} end |
Instance Method Details
#parse(args = ARGV) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ghost/cli.rb', line 18 def parse(args = ARGV) parser.parse! args arg = args.shift.to_s if (task = tasks[arg]) task.perform(*args) else abort "No such task" end rescue Errno::EACCES abort "Insufficient privileges. Try using `sudo` or running as root." end |
#tasks ⇒ Object
54 55 56 |
# File 'lib/ghost/cli/task.rb', line 54 def tasks @tasks ||= Hash[self.class.tasks.map { |name, task| [name, task.new(store, out)] }] end |