Module: OsCtl::Cli::Devices
Constant Summary collapse
- DEVICES_FIELDS =
%i[ type major minor mode name inherit inherited ].freeze
Instance Method Summary collapse
- #do_device_add(cmd, cmd_opts) ⇒ Object
- #do_device_chmod(cmd, cmd_opts) ⇒ Object
- #do_device_delete(cmd, cmd_opts) ⇒ Object
- #do_device_inherit(cmd, cmd_opts) ⇒ Object
- #do_device_list(cmd, cmd_opts) ⇒ Object
- #do_device_promote(cmd, cmd_opts) ⇒ Object
- #do_device_replace(cmd, cmd_opts) ⇒ Object
- #do_device_set_inherit(cmd, cmd_opts) ⇒ Object
- #do_device_unset_inherit(cmd, cmd_opts) ⇒ Object
Instance Method Details
#do_device_add(cmd, cmd_opts) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/osctl/cli/devices.rb', line 36 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: 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
65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/osctl/cli/devices.rb', line 65 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: 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
52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/osctl/cli/devices.rb', line 52 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: cmd_opts.merge( type: args[1], major: args[2], minor: args[3], recursive: opts[:recursive] )) end |
#do_device_inherit(cmd, cmd_opts) ⇒ Object
92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/osctl/cli/devices.rb', line 92 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: 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 29 30 31 32 33 34 |
# File 'lib/osctl/cli/devices.rb', line 13 def do_device_list(cmd, cmd_opts) param_selector = OsCtl::Lib::Cli::ParameterSelector.new( all_params: DEVICES_FIELDS ) if opts[:list] puts param_selector return end fmt_opts = { layout: :columns, cols: param_selector.parse_option(opts[:output]) } fmt_opts[:header] = false if opts['hide-header'] osctld_fmt( cmd, cmd_opts:, fmt_opts: ) end |
#do_device_promote(cmd, cmd_opts) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/osctl/cli/devices.rb', line 80 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: cmd_opts.merge( type: args[1], major: args[2], minor: args[3] )) end |
#do_device_replace(cmd, cmd_opts) ⇒ Object
128 129 130 131 132 |
# File 'lib/osctl/cli/devices.rb', line 128 def do_device_replace(cmd, cmd_opts) osctld_fmt(cmd, cmd_opts: cmd_opts.merge( devices: JSON.parse($stdin.read)['devices'] )) end |
#do_device_set_inherit(cmd, cmd_opts) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 |
# File 'lib/osctl/cli/devices.rb', line 104 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: cmd_opts.merge( type: args[1], major: args[2], minor: args[3] )) end |
#do_device_unset_inherit(cmd, cmd_opts) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/osctl/cli/devices.rb', line 116 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: cmd_opts.merge( type: args[1], major: args[2], minor: args[3] )) end |