public static ADRCommand Parse(string[] args) { var command = new ADRCommand(); if (args.Length == 0 || Utility.InvariantEquals("help", args[0])) { command.Command = "help"; command.Arguments = args.Skip(1).ToArray(); return(command); } if (Utility.InvariantEquals("init", args[0])) { command.Command = "init"; command.Arguments = args.Skip(1).ToArray(); return(command); } if (Utility.InvariantEquals("new", args[0])) { if (args.Length == 1) { command.Command = "invalid"; command.Arguments = new string[] { "you need to supply a name for the new record", "" }; return(command); } command.Command = "new"; command.Arguments[0] = string.Join(" ", args.Skip(1).ToArray()); return(command); } command.Command = "invalid"; command.Arguments[0] = string.Join(" ", args.ToArray()); return(command); }
private static void ShowHelp(ADRCommand c = null) { Utility.WriteLine(@"ADR - Architecture Descision Records tool Description: A command line tool for creating architecure decision records. You can read more about ADRs here https://adr.github.io/ Usage: adr [command] [options] Commands: init initialises a repository for ADR items in the current directory. new [NAME] the name of the record to be created help show this message and exit "); if (c != null) { Utility.WriteLine("Invalid command: " + c.Arguments[0]); } }
static void Main(string[] args) { try { var c = ADRCommand.Parse(args); if (c.Command == "invalid") { ShowHelp(c); return; } if (c.Command == "help") { ShowHelp(); return; } if (c.Command == "init") { var currentDir = Environment.CurrentDirectory; var repo = DAL.InitRepository(currentDir); Utility.WriteLine("Created ADR repository at:" + repo); return; } if (c.Command == "new") { var adr = new Models.ADR(); adr.Title = string.Join(" ", c.Arguments); var recordPath = DAL.SaveADR(adr); Utility.WriteLine("Creating a new record at:" + recordPath); return; } } catch (Exception ex) { Utility.WriteErrorLine(ex.Message); } }