Class: SvCtl::Cli::Command

Inherits:
OsCtl::Lib::Cli::Command
  • Object
show all
Defined in:
lib/svctl/cli/command.rb

Class Method Summary collapse

Instance Method Summary collapse

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

#disableObject



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

#enableObject



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_completionObject



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_allObject



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|
      sprintf('%-10s', sv_runlevels.include?(rlv) ? rlv : '')
    end.join('  ')

    puts sprintf('%-20s    %s', s.name, rlv_line)
  end
end

#list_protectedObject



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_runlevelsObject



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_servicesObject



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

#protectObject



49
50
51
52
# File 'lib/svctl/cli/command.rb', line 49

def protect
  require_args!('service')
  SvCtl.protect(args[0])
end

#runlevelObject



69
70
71
72
# File 'lib/svctl/cli/command.rb', line 69

def runlevel
  require_args!
  puts SvCtl.runlevel
end

#switchObject



74
75
76
77
# File 'lib/svctl/cli/command.rb', line 74

def switch
  require_args!('runlevel')
  SvCtl.switch(args[0])
end

#unprotectObject



54
55
56
57
# File 'lib/svctl/cli/command.rb', line 54

def unprotect
  require_args!('service')
  SvCtl.unprotect(args[0])
end