Class: Envo::CmdUnset
- Inherits:
-
Object
- Object
- Envo::CmdUnset
- Defined in:
- lib/envo/cmd_unset.rb
Constant Summary collapse
- Name =
'unset'
Instance Attribute Summary collapse
-
#names ⇒ Object
readonly
Returns the value of attribute names.
Class Method Summary collapse
- .parse_cli(args) ⇒ Object
- .parse_tokens(tokens, opts) ⇒ Object
- .register_cli_parser(parser) ⇒ Object
- .register_help(help) ⇒ Object
- .register_script_parser(parser) ⇒ Object
Instance Method Summary collapse
- #execute(ctx) ⇒ Object
-
#initialize(names) ⇒ CmdUnset
constructor
A new instance of CmdUnset.
Constructor Details
Instance Attribute Details
#names ⇒ Object (readonly)
Returns the value of attribute names.
30 31 32 |
# File 'lib/envo/cmd_unset.rb', line 30 def names @names end |
Class Method Details
.parse_cli(args) ⇒ Object
16 17 18 19 |
# File 'lib/envo/cmd_unset.rb', line 16 def self.parse_cli(args) opts = CliParser.filter_opts(args) ParsedCmd.new(CmdUnset.new(args), opts) end |
.parse_tokens(tokens, opts) ⇒ Object
21 22 23 |
# File 'lib/envo/cmd_unset.rb', line 21 def self.parse_tokens(tokens, opts) ParsedCmd.new(CmdUnset.new(tokens), opts) end |
.register_cli_parser(parser) ⇒ Object
8 9 10 |
# File 'lib/envo/cmd_unset.rb', line 8 def self.register_cli_parser(parser) parser.add_cmd(Name, ->(cmd, args) { parse_cli(args) }) end |
.register_help(help) ⇒ Object
4 5 6 |
# File 'lib/envo/cmd_unset.rb', line 4 def self.register_help(help) help.add_cmd 'unset <name> ...', "unset values of one or more environment variables" end |
.register_script_parser(parser) ⇒ Object
12 13 14 |
# File 'lib/envo/cmd_unset.rb', line 12 def self.register_script_parser(parser) parser.add_cmd(Name, ->(cmd, tokens, opts) { parse_tokens(tokens, opts) }) end |
Instance Method Details
#execute(ctx) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/envo/cmd_unset.rb', line 32 def execute(ctx) @names.each do |name| ename = ctx.(name) raw_old_val = ctx.raw_get(ename) if raw_old_val ctx.unset(ename) else raise Envo::Error.new "unset: no such var '#{ename}'" if !ctx.force? end end end |