Class: SvCtl::Cli::Command
- Inherits:
-
OsCtl::Lib::Cli::Command
- Object
- OsCtl::Lib::Cli::Command
- SvCtl::Cli::Command
- Defined in:
- lib/svctl/cli/command.rb
Class Method Summary collapse
Instance Method Summary collapse
- #disable ⇒ Object
- #enable ⇒ Object
- #gen_bash_completion ⇒ Object
- #list_all ⇒ Object
- #list_protected ⇒ Object
- #list_runlevels ⇒ Object
- #list_services ⇒ Object
- #protect ⇒ Object
- #runlevel ⇒ Object
- #switch ⇒ Object
- #unprotect ⇒ Object
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 do |global_opts, opts, args| cmd = new(global_opts, opts, args) cmd.method(method).call end end |
Instance Method Details
#disable ⇒ Object
44 45 46 47 |
# File 'lib/svctl/cli/command.rb', line 44 def disable require_args!('service', optional: %w[runlevel]) SvCtl.disable(args[0], args[1] || 'current') end |
#enable ⇒ Object
39 40 41 42 |
# File 'lib/svctl/cli/command.rb', line 39 def enable require_args!('service', optional: %w[runlevel]) SvCtl.enable(args[0], args[1] || 'current') end |
#gen_bash_completion ⇒ Object
79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/svctl/cli/command.rb', line 79 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
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/svctl/cli/command.rb', line 12 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| format('%-10s', sv_runlevels.include?(rlv) ? rlv : '') end.join(' ') puts format('%-30s %s', s.name, rlv_line) end end |
#list_protected ⇒ Object
59 60 61 62 |
# File 'lib/svctl/cli/command.rb', line 59 def list_protected require_args! SvCtl.protected_services.each { |name| puts name } end |
#list_runlevels ⇒ Object
64 65 66 67 |
# File 'lib/svctl/cli/command.rb', line 64 def list_runlevels require_args! SvCtl.runlevels.each { |v| puts v } end |
#list_services ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/svctl/cli/command.rb', line 25 def list_services if opts[:all] require_args! list_all else require_args!(optional: %w[runlevel]) SvCtl.runlevel_services(args[0] || 'current').each do |s| puts s.name end end end |
#protect ⇒ Object
49 50 51 52 |
# File 'lib/svctl/cli/command.rb', line 49 def protect require_args!('service') SvCtl.protect(args[0]) end |
#runlevel ⇒ Object
69 70 71 72 |
# File 'lib/svctl/cli/command.rb', line 69 def runlevel require_args! puts SvCtl.runlevel end |