Class: Envo::CmdRun
- Inherits:
-
Object
- Object
- Envo::CmdRun
- Defined in:
- lib/envo/cmd_run.rb
Defined Under Namespace
Modules: Opts
Constant Summary collapse
- Name =
'run'
Instance Attribute Summary collapse
-
#script ⇒ Object
readonly
Returns the value of attribute script.
Class Method Summary collapse
- .parse_cli(args) ⇒ Object
- .register_cli_parser(parser) ⇒ Object
- .register_help(help) ⇒ Object
- .register_script_parser(parser) ⇒ Object
Instance Method Summary collapse
- #execute(ctx) ⇒ Object
-
#initialize(script) ⇒ CmdRun
constructor
A new instance of CmdRun.
Constructor Details
#initialize(script) ⇒ CmdRun
Returns a new instance of CmdRun.
25 26 27 |
# File 'lib/envo/cmd_run.rb', line 25 def initialize(script) @script = script end |
Instance Attribute Details
#script ⇒ Object (readonly)
Returns the value of attribute script.
29 30 31 |
# File 'lib/envo/cmd_run.rb', line 29 def script @script end |
Class Method Details
.parse_cli(args) ⇒ Object
19 20 21 22 23 |
# File 'lib/envo/cmd_run.rb', line 19 def self.parse_cli(args) opts = CliParser.filter_opts(args) raise Envo::Error.new "run: provide a single script name. Use 'run <script>'" if args.size != 1 ParsedCmd.new(CmdRun.new(args[0]), opts) end |
.register_cli_parser(parser) ⇒ Object
12 13 14 |
# File 'lib/envo/cmd_run.rb', line 12 def self.register_cli_parser(parser) parser.add_cmd(Name, ->(cmd, args) { parse_cli(args) }) end |
.register_help(help) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/envo/cmd_run.rb', line 4 def self.register_help(help) help.add_cmd 'run <script>', <<~EOF run a script of envo commands if script is a relative or an absolute path, it tries to load the exact filename otherwise it searches for '<script>.envoscript' in .envo/ subdirs of current tree and in <home>/.envo/ EOF end |
.register_script_parser(parser) ⇒ Object
16 17 |
# File 'lib/envo/cmd_run.rb', line 16 def self.register_script_parser(parser) end |
Instance Method Details
#execute(ctx) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/envo/cmd_run.rb', line 44 def execute(ctx) file = ctx.find_script(@script) lines = ctx.load_script(file) parser = ScriptParser.new(Opts) [ CmdShow, CmdSet, CmdReset, CmdUnset, CmdList, CmdClean, CmdCopy, CmdSwap, CmdPath, CmdRun, ].each { |cmd| cmd.register_script_parser(parser) } res = parser.parse(lines) scope = ctx.new_scope({interact: :force}) scope.execute(res) end |