Class: SvCtl::Cli::Command
- Inherits:
-
Object
- Object
- SvCtl::Cli::Command
- Defined in:
- lib/svctl/cli/command.rb
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
- #disable ⇒ Object
- #enable ⇒ Object
- #gen_bash_completion ⇒ Object
-
#initialize(global_opts, opts, args) ⇒ Command
constructor
A new instance of Command.
- #list_all ⇒ Object
- #list_runlevels ⇒ Object
- #list_services ⇒ Object
- #runlevel ⇒ Object
- #switch ⇒ Object
Constructor Details
#initialize(global_opts, opts, args) ⇒ Command
Returns a new instance of Command
14 15 16 17 18 |
# File 'lib/svctl/cli/command.rb', line 14 def initialize(global_opts, opts, args) @gopts = global_opts @opts = opts @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args
12 13 14 |
# File 'lib/svctl/cli/command.rb', line 12 def args @args end |
#gopts ⇒ Object (readonly)
Returns the value of attribute gopts
12 13 14 |
# File 'lib/svctl/cli/command.rb', line 12 def gopts @gopts end |
#opts ⇒ Object (readonly)
Returns the value of attribute opts
12 13 14 |
# File 'lib/svctl/cli/command.rb', line 12 def opts @opts end |
Class Method Details
.run(method) ⇒ Object
5 6 7 8 9 10 |
# File 'lib/svctl/cli/command.rb', line 5 def self.run(method) Proc.new do |global_opts, opts, args| cmd = new(global_opts, opts, args) cmd.method(method).call end end |
Instance Method Details
#disable ⇒ Object
49 50 51 52 |
# File 'lib/svctl/cli/command.rb', line 49 def disable raise GLI::BadCommandLine, 'missing argument <service>' unless args[0] SvCtl.disable(args[0], args[1] || 'current') end |
#enable ⇒ Object
44 45 46 47 |
# File 'lib/svctl/cli/command.rb', line 44 def enable raise GLI::BadCommandLine, 'missing argument <service>' unless args[0] SvCtl.enable(args[0], args[1] || 'current') end |
#gen_bash_completion ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/svctl/cli/command.rb', line 67 def gen_bash_completion c = OsCtl::Lib::Cli::Completion::Bash.new(Cli::App.get) services = 'ls -1 /etc/runit/services' runlevels = 'ls -1 /etc/runit/runsvdir | grep -v previous' c.arg(cmd: :all, name: :service, expand: services) c.arg(cmd: :all, name: :runlevel, expand: runlevels) puts c.generate end |
#list_all ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/svctl/cli/command.rb', line 20 def list_all all_runlevels = SvCtl.runlevels SvCtl.all_services.sort.each do |s| sv_runlevels = s.runlevels rlv_line = all_runlevels.map do |rlv| sprintf('%-10s', sv_runlevels.include?(rlv) ? rlv : '') end.join(' ') puts sprintf('%-20s %s', s.name, rlv_line) end end |
#list_runlevels ⇒ Object
54 55 56 |
# File 'lib/svctl/cli/command.rb', line 54 def list_runlevels SvCtl.runlevels.each { |v| puts v } end |
#list_services ⇒ Object
33 34 35 36 37 38 39 40 41 42 |
# File 'lib/svctl/cli/command.rb', line 33 def list_services if opts[:all] list_all else SvCtl.runlevel_services(args[0] || 'current').each do |s| puts s.name end end end |