protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); Current.MainWindow = new MainWindow(); _notify.ShowMessage("Metatool starting..."); var scaffold = new Scaffold(_logger); scaffold.CommonSetup(_config); ConfigNotify(scaffold); _logger.LogInformation($"Registered MetatoolDir: {Environment.GetEnvironmentVariable("MetatoolDir")}"); _logger.LogInformation("Metatool started!"); }
private void ConfigNotify(Scaffold scaffolder) { _notify.AddContextMenuItem("Show Log", e => { if (e.IsChecked) { ConsoleExt.ShowConsole(); } else { ConsoleExt.HideConsole(); } }, null, true, _hostEnv.IsDevelopment()); _notify.AddContextMenuItem("Auto Start", e => AutoStartManager.IsAutoStart = e.IsChecked, null, true, AutoStartManager.IsAutoStart); _notify.AddContextMenuItem("Register", e => { scaffolder.Register(); }); _notify.ShowMessage("Metatool started!"); }
public int Run() { var app = new CommandLineApplication() { Name = "metatool", Description = "tools for Windows", ExtendedHelpText = "===Metaseed Metatool===" }; app.HelpOption(inherited: true); app.OnExecute(() => { // without sub command App.RunApp(); Services.GetOrCreate <PluginManager>().InitPlugins(); }); app.Command("new", configCmd => { configCmd.OnExecute(() => { Console.WriteLine("Please specify a subcommand"); configCmd.ShowHelp(); return(1); }); configCmd.Command("script", c => { c.Description = "Creates a sample script tool along with the files needed to launch and debug the script."; var fileName = c.Argument("name", "The name of the tool script to be created.") .IsRequired(errorMessage: "please set the tool name \nusage: metatool new script <name>"); var cwd = c.Option("-dir |--directory <dir>", "The directory to initialize the tool scripts. Defaults to current directory.", CommandOptionType.SingleValue).Accepts(v => v.ExistingDirectory()); c.HelpOption(HelpOptionTemplate); c.OnExecute(() => { var scaffolder = new Scaffold(_logger); scaffolder.InitTemplate(fileName.Value, cwd.Value()); }); }); configCmd.Command("lib", c => { c.Description = "Creates a sample lib(dll) tool along with the files needed to launch and debug the csharp project."; var fileName = c.Argument("name", "The name of the tool to be created."); var cwd = c.Option("-dir |--directory <dir>", "The directory to initialize the tool. Defaults to current directory.", CommandOptionType.SingleValue).Accepts(v => v.ExistingDirectory()); c.HelpOption(HelpOptionTemplate); c.OnExecute(() => { var scaffolder = new Scaffold(_logger); scaffolder.InitTemplate(fileName.Value, cwd.Value(), false); }); }); }); app.Command("run", app => { app.Description = "run the script or lib with metatool"; var cmdArg = app.Argument("path", "The dir and name of the script(.csx) to be created."); cmdArg.Validators.Add(new FileNameValidator()); app.HelpOption(HelpOptionTemplate); app.OnExecute(() => { var fullPath = cmdArg.Value; if (!File.Exists(fullPath)) { fullPath = Path.Combine(Context.CurrentDirectory, fullPath); } if (fullPath.EndsWith(".dll")) { try { Services.GetOrCreate <PluginManager>().LoadDll(fullPath); } catch (Exception ex) { _logger.LogError(ex, $"Error while loading tool {fullPath}! No tools loaded! Please fix it then restart!"); } } else if (fullPath.EndsWith(".csx")) { var assemblyName = Path.GetFileName(Path.GetDirectoryName(fullPath)); _logger.LogInformation($"Compile&Run: {fullPath}, {assemblyName}"); Services.GetOrCreate <PluginManager>().BuildReload(fullPath, assemblyName, false); } App.RunApp(); }); }); // on windows we have command to register .csx files to be executed by dotnet-script app.Command("register", c => { c.Description = "Register .csx file handler to enable running scripts directly"; c.HelpOption(HelpOptionTemplate); c.OnExecute(() => { var scaffolder = new Scaffold(_logger); scaffolder.Register(); }); }); return(app.Execute(_args)); }