Class: VpsAdminOS::Converter::Cli::Command
- Inherits:
-
Object
- Object
- VpsAdminOS::Converter::Cli::Command
- Defined in:
- lib/vpsadminos-converter/cli/command.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#gopts ⇒ Object
readonly
Returns the value of attribute gopts.
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(global_opts, opts, args) ⇒ Command
constructor
A new instance of Command.
- #require_args!(*v) ⇒ Object
Constructor Details
#initialize(global_opts, opts, args) ⇒ Command
Returns a new instance of Command.
14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/vpsadminos-converter/cli/command.rb', line 14 def initialize(global_opts, opts, args) @gopts = global_opts @opts = opts @args = args if gopts['log-file'] OsCtl::Lib::Logger.setup(:io, io: File.open(gopts['log-file'], 'a')) else OsCtl::Lib::Logger.setup(:none) end end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
12 13 14 |
# File 'lib/vpsadminos-converter/cli/command.rb', line 12 def args @args end |
#gopts ⇒ Object (readonly)
Returns the value of attribute gopts.
12 13 14 |
# File 'lib/vpsadminos-converter/cli/command.rb', line 12 def gopts @gopts end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
12 13 14 |
# File 'lib/vpsadminos-converter/cli/command.rb', line 12 def opts @opts end |
Class Method Details
.run(klass, method) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/vpsadminos-converter/cli/command.rb', line 5 def self.run(klass, method) Proc.new do |global_opts, opts, args| cmd = klass.new(global_opts, opts, args) cmd.method(method).call end end |
Instance Method Details
#require_args!(*v) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vpsadminos-converter/cli/command.rb', line 27 def require_args!(*v) if v.count == 1 && v.first.is_a?(Array) required = v.first else required = v end return if args.count >= required.count arg = required[ args.count ] raise GLI::BadCommandLine, "missing argument <#{arg}>" end |