class Envo::CmdRun

Constants

Name

Attributes

script[R]

Public Class Methods

new(script) click to toggle source
# File lib/envo/cmd_run.rb, line 25
def initialize(script)
  @script = script
end
parse_cli(args) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# File lib/envo/cmd_run.rb, line 16
def self.register_script_parser(parser)
end

Public Instance Methods

execute(ctx) click to toggle source
# 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