Beispiel #1
0
        public static string Load(string scriptPath)
        {
            Std.Info($"Running script '{scriptPath}'");
            if (!File.Exists(scriptPath))
            {
                throw new ScriptException($"Cannot file script '{scriptPath}'");
            }

            return(File.ReadAllText(scriptPath));
        }
Beispiel #2
0
 public override void Execute(XElement model, Context ctx)
 {
     if (string.IsNullOrEmpty(rest))
     {
         Std.Info("");
     }
     else
     {
         var expanded = ExpandVars(rest, model, ctx);
         Std.Info(expanded);
     }
 }
Beispiel #3
0
        public override void Execute(XElement model, Context ctx)
        {
            var newFilename = ExpandVars(_quoted, model, ctx);

            EnsureFolderExists(newFilename);
            Std.Info($"Output is '{newFilename}'");
            var old = ctx.Output;

            ctx.Output = new StreamWriter(newFilename, append: false);
            old.Flush();
            old.Close();
        }
Beispiel #4
0
        static int Main(string[] argv)
        {
            var args = argv.ToList();
            var ctx  = new Context {
                Output = Console.Out
            };

            var scriptPath = StringArg(args, "--script");

            if (string.IsNullOrEmpty(scriptPath))
            {
                Std.Error("script name/path must be supplied via the --script argument");
                return(1);
            }

            try
            {
                string modelPath = args.FirstOrDefault();
                if (string.IsNullOrEmpty(modelPath))
                {
                    Std.Error("Expected model file name/path to be supplied");
                    return(2);
                }
                args.RemoveAt(0);

                XDocument model = XDocument.Load(modelPath);
                var       root  = model.Root;
                root.Add(new XAttribute("model-path", modelPath));
                root.Add(new XAttribute("script-path", scriptPath));
                root.Add(new XAttribute("datetime-utc", DateTime.UtcNow.ToString("u")));
                MergeArgsAsAttributes(args, root); // extra arguments AFTER the model file are added as attributes to the root element
                Scripts.Run(scriptPath, root, ctx);
                return(0);
            }
            catch (Exception ex)
            {
                Std.Error(ex.ToString());
                return(9);
            }
        }