Class: VpsAdminOS::Converter::Cli::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/vpsadminos-converter/cli/command.rb

Direct Known Subclasses

Vz6::Base

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#argsObject (readonly)

Returns the value of attribute args



12
13
14
# File 'lib/vpsadminos-converter/cli/command.rb', line 12

def args
  @args
end

#goptsObject (readonly)

Returns the value of attribute gopts



12
13
14
# File 'lib/vpsadminos-converter/cli/command.rb', line 12

def gopts
  @gopts
end

#optsObject (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

Parameters:

  • v (Array)

    list of required arguments

Raises:

  • (GLI::BadCommandLine)


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