using System; using System.Collections.Generic; using ln.build.commands; namespace ln.build.pipeline { public abstract class StageCommand { public string Name { get; } public StageCommand(string name) { Name = name; } public abstract void Run(Stage stage); static Dictionary> commandFactories = new Dictionary>(); public static StageCommand Create(string cmdline) { string[] tokens = cmdline.Split(new char[]{' ','\t'}, 2); if (commandFactories.TryGetValue(tokens[0],out Func factory)) { return factory(tokens[1]); } throw new Exception(string.Format("can't find factory for command keyword '{0}'", tokens[0])); } static StageCommand() { commandFactories.Add("SH", (args) => new ShellCommand(args)); commandFactories.Add("DOTNET", (args) => new DotNetCommand(args)); commandFactories.Add("GITEA", (args) => new DotNetCommand(args)); commandFactories.Add("RELEASE", (args) => new ReleaseCommand(args)); } } }