public static void Process(string[] args) { try { if (args.Length < 1) { Console.WriteLine(GenerateUsage()); return; } foreach (Type t in Assembly.GetExecutingAssembly().GetTypes()) { CliContainerAttribute containerAttribute = t.GetCustomAttribute <CliContainerAttribute>(); if (containerAttribute != null) { if (containerAttribute.Name == args[0]) { string[] newArgs = new string[args.Length - 1]; Array.Copy(args, 1, newArgs, 0, newArgs.Length); ProcessMethods(t, newArgs); return; } } } Console.WriteLine(GenerateUsage()); } catch (Exception e) { if (Constants.Spinner.IsRunning()) { Constants.Spinner.Stop(IOStatus.ERROR, $"Error: {Constants.Spinner.Message}!"); } throw; } }
private static string GenerateContainerUsage(Type type) { StringBuilder sb = new StringBuilder(); CliContainerAttribute containerAttribute = type.GetCustomAttribute <CliContainerAttribute>(); sb.AppendLine($"Help for: {GlobalConfig.CmdName} {containerAttribute.Name}"); sb.AppendLine(""); sb.AppendLine("Available Subcommands:"); sb.AppendLine(""); foreach (MethodInfo info in type.GetMethods()) { CliCommandAttribute commandAttribute = info.GetCustomAttribute <CliCommandAttribute>(); if (commandAttribute != null) { sb.AppendLine($"\t-{commandAttribute.Name}"); } } sb.AppendLine(""); sb.AppendLine("In order to retrieve help for a command enter:"); sb.AppendLine($"{GlobalConfig.CmdName} {containerAttribute.Name} <command> help"); return(sb.ToString()); }
private static string GenerateCommandUsage(Type type, MethodInfo info) { StringBuilder sb = new StringBuilder(); CliContainerAttribute containerAttribute = type.GetCustomAttribute <CliContainerAttribute>(); CliCommandAttribute commandAttribute = info.GetCustomAttribute <CliCommandAttribute>(); sb.AppendLine($"Help for {GlobalConfig.CmdName} {containerAttribute.Name} {commandAttribute.Name}"); sb.AppendLine(""); sb.AppendLine("Usage (<param> is required, [param] is optional):"); sb.AppendLine(""); sb.Append($"{GlobalConfig.CmdName} "); sb.Append($"{containerAttribute.Name} "); sb.Append($"{commandAttribute.Name} "); foreach (ParameterInfo pInfo in info.GetParameters()) { if (DBNull.Value.Equals(pInfo.DefaultValue)) { sb.Append($"<{pInfo.ParameterType.ToString().Replace(pInfo.ParameterType.Namespace.ToString() + ".", "")} {pInfo.Name}> "); } else { sb.Append($"[{pInfo.ParameterType.ToString().Replace(pInfo.ParameterType.Namespace.ToString() + ".", "")} {pInfo.Name}] "); } } return(sb.ToString()); }
private static string GenerateUsage() { StringBuilder sb = new StringBuilder(); sb.AppendLine($"General usage for {GlobalConfig.CmdName}:"); sb.AppendLine(""); foreach (Type t in Assembly.GetExecutingAssembly().GetTypes()) { CliContainerAttribute containerAttribute = t.GetCustomAttribute <CliContainerAttribute>(); if (containerAttribute != null) { sb.AppendLine($"\t-{containerAttribute.Name}"); } } sb.AppendLine(""); sb.AppendLine($"Enter \"{GlobalConfig.CmdName} <cmd> help\" to receive help"); return(sb.ToString()); }