Module: OsCtl::Cli::Devices

Included in:
Container, Group
Defined in:
lib/osctl/cli/devices.rb

Constant Summary collapse

DEVICES_FIELDS =
%i(
  type
  major
  minor
  mode
  name
  inherit
  inherited
)

Instance Method Summary collapse

Instance Method Details

#do_device_add(cmd, cmd_opts) ⇒ Object



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/osctl/cli/devices.rb', line 30

def do_device_add(cmd, cmd_opts)
  unless %w(char block).include?(args[1])
    raise GLI::BadCommandLine, 'device type has to be one of: block, char'
  end

  osctld_fmt(cmd, cmd_opts.merge(
    type: args[1],
    major: args[2],
    minor: args[3],
    mode: args[4],
    dev_name: args[5],
    inherit: opts[:inherit],
    parents: opts[:parents]
  ))
end

#do_device_chmod(cmd, cmd_opts) ⇒ Object



59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/osctl/cli/devices.rb', line 59

def do_device_chmod(cmd, cmd_opts)
  unless %w(char block).include?(args[1])
    raise GLI::BadCommandLine, 'device type has to be one of: block, char'
  end

  osctld_fmt(cmd, cmd_opts.merge(
    type: args[1],
    major: args[2],
    minor: args[3],
    mode: args[4] == '-' ? '' : args[4],
    parents: opts[:parents],
    recursive: opts[:recursive]
  ))
end

#do_device_delete(cmd, cmd_opts) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/osctl/cli/devices.rb', line 46

def do_device_delete(cmd, cmd_opts)
  unless %w(char block).include?(args[1])
    raise GLI::BadCommandLine, 'device type has to be one of: block, char'
  end

  osctld_fmt(cmd, cmd_opts.merge(
    type: args[1],
    major: args[2],
    minor: args[3],
    recursive: opts[:recursive]
  ))
end

#do_device_inherit(cmd, cmd_opts) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/osctl/cli/devices.rb', line 86

def do_device_inherit(cmd, cmd_opts)
  unless %w(char block).include?(args[1])
    raise GLI::BadCommandLine, 'device type has to be one of: block, char'
  end

  osctld_fmt(cmd, cmd_opts.merge(
    type: args[1],
    major: args[2],
    minor: args[3],
  ))
end

#do_device_list(cmd, cmd_opts) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/osctl/cli/devices.rb', line 13

def do_device_list(cmd, cmd_opts)
  if opts[:list]
    puts DEVICES_FIELDS.join("\n")
    return
  end

  fmt_opts = {layout: :columns}
  fmt_opts[:header] = false if opts['hide-header']

  osctld_fmt(
    cmd,
    cmd_opts,
    opts[:output] ? opts[:output].split(',').map(&:to_sym) : nil,
    fmt_opts
  )
end

#do_device_promote(cmd, cmd_opts) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
# File 'lib/osctl/cli/devices.rb', line 74

def do_device_promote(cmd, cmd_opts)
  unless %w(char block).include?(args[1])
    raise GLI::BadCommandLine, 'device type has to be one of: block, char'
  end

  osctld_fmt(cmd, cmd_opts.merge(
    type: args[1],
    major: args[2],
    minor: args[3],
  ))
end

#do_device_replace(cmd, cmd_opts) ⇒ Object



122
123
124
125
126
# File 'lib/osctl/cli/devices.rb', line 122

def do_device_replace(cmd, cmd_opts)
  osctld_fmt(cmd, cmd_opts.merge(
    devices: JSON.parse(STDIN.read)['devices'],
  ))
end

#do_device_set_inherit(cmd, cmd_opts) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
# File 'lib/osctl/cli/devices.rb', line 98

def do_device_set_inherit(cmd, cmd_opts)
  unless %w(char block).include?(args[1])
    raise GLI::BadCommandLine, 'device type has to be one of: block, char'
  end

  osctld_fmt(cmd, cmd_opts.merge(
    type: args[1],
    major: args[2],
    minor: args[3],
  ))
end

#do_device_unset_inherit(cmd, cmd_opts) ⇒ Object



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/osctl/cli/devices.rb', line 110

def do_device_unset_inherit(cmd, cmd_opts)
  unless %w(char block).include?(args[1])
    raise GLI::BadCommandLine, 'device type has to be one of: block, char'
  end

  osctld_fmt(cmd, cmd_opts.merge(
    type: args[1],
    major: args[2],
    minor: args[3],
  ))
end