Skip to content

Commit

Permalink
Extend help text for file operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Andreas Wäscher committed Dec 20, 2017
1 parent 4839e68 commit 7e07969
Showing 1 changed file with 51 additions and 33 deletions.
84 changes: 51 additions & 33 deletions grr/CommandLineOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

namespace grr
{
class CommandLineOptions
partial class CommandLineOptions
{
public const string ListCommand = "list";
public const string ChangeDirectoryCommand = "cd";
Expand All @@ -17,24 +17,24 @@ class CommandLineOptions
public const string HelpCommand = "help";
public const char HelpCommandChar = '?';

[VerbOption(ListCommand, HelpText = "Lists the repositories found by RepoZ including their current branch and the corresponding status.")]
public FilterOptions ListOptions { get; set; }
[VerbOption(ListCommand, HelpText = "(Default) Lists the repositories found by RepoZ including their current branch and the corresponding status. Can be omitted like shown in the examples below.")]
public RepositoryFilterOptions ListOptions { get; set; }

[VerbOption(ChangeDirectoryCommand, HelpText = "Navigates to the directory of a given repository.")]
public FilterOptions ChangeDirectoryOptions { get; set; }
[VerbOption(ChangeDirectoryCommand, HelpText = "Causes the command line interface to navigate to the directory of a given repository.")]
public RepositoryFilterOptions ChangeDirectoryOptions { get; set; }

[VerbOption(OpenDirectoryCommand, HelpText = "Opens the directory of a given repository with the default shell.")]
public FilterOptions OpenDirectoryOptions { get; set; }
[VerbOption(OpenDirectoryCommand, HelpText = "Opens the directory or a file of a given repository with the operating system's default application.")]
public RepositoryFilterOptions OpenDirectoryOptions { get; set; }

[Option(HelpCommandChar, HelpCommand, HelpText = "Shows this help page")]
public bool Help { get; set; }

public static string[] GetKnownCommands() => new string[] { ListCommand, ChangeDirectoryCommand, OpenDirectoryCommand, HelpCommand, HelpCommandChar.ToString() };

public static bool IsKnownArgument(string arg)
{
var args = new string[] { ListCommand, ChangeDirectoryCommand, OpenDirectoryCommand, HelpCommand, HelpCommandChar.ToString() };
arg = arg.TrimStart('-').TrimStart('/');

return args.Contains(arg, StringComparer.OrdinalIgnoreCase);
return GetKnownCommands().Contains(arg, StringComparer.OrdinalIgnoreCase);
}

[HelpOption]
Expand All @@ -49,50 +49,68 @@ public static string GetUsage()
MaximumDisplayWidth = 100
};

string knownCommandsPiped = string.Join("|", GetKnownCommands());
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine("USAGE:");
help.AddPreOptionsLine($" grr [{knownCommandsPiped}] [repository name or filter] [file name or filter]");
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine(" ");
help.AddPreOptionsLine(" ");

help.AddPreOptionsLine("COMMANDS:");
help.AddOptions(new CommandLineOptions());

help.AddPostOptionsLine("Note: To keep the examples short, \"Repo\" is used as placeholder for a repository name");
help.AddPostOptionsLine(" like \"RepoZ\" or \"NSidekick\", for example.");
help.AddPostOptionsLine(" ");
help.AddPostOptionsLine("FILTERS:");
help.AddPostOptionsLine("");
help.AddPostOptionsLine(" Repository name or filter:");
help.AddPostOptionsLine(" The name of a repository or a RegEx filter expression to find matching repositories.");
help.AddPostOptionsLine("");
help.AddPostOptionsLine(" File name or filter:");
help.AddPostOptionsLine(" The name of a file or a filter pattern to find matching files of a given repository.");
help.AddPostOptionsLine(" Append \"--recursive\" or short \"-r\" to search files recursively in sub directories.");
help.AddPostOptionsLine("");
help.AddPostOptionsLine("");
help.AddPostOptionsLine("");

help.AddPostOptionsLine("Usage:");

help.AddPostOptionsLine("EXAMPLES:");
help.AddPostOptionsLine(" (to keep the examples short, \"Repo\" is used as placeholder for a repository name");
help.AddPostOptionsLine(" like \"RepoZ\" or \"NSidekick\", for example)");
help.AddPostOptionsLine("");

help.AddPostOptionsLine("Basics:");
help.AddPostOptionsLine(" grr \t\t\tLists all repositories found in RepoZ including their status");
help.AddPostOptionsLine(" grr list Repo \tShows the status of a given repository (option \"list\" is optional)");
help.AddPostOptionsLine(" grr list Repo \tShows the status of a given repository (command \"list\" is optional)");
help.AddPostOptionsLine(" grr cd Repo \t\tNavigates to the main directory of a given repository");
help.AddPostOptionsLine(" grr open Repo \tOpens the main directory of a given repository (in Windows Explorer)");
help.AddPostOptionsLine("");
help.AddPostOptionsLine("File operations in given repositories:");
help.AddPostOptionsLine(" grr list Repo *.txt \tLists all text files in the given repository matching the filter *.txt");
help.AddPostOptionsLine(" grr open Repo *.sln \tOpens the first Visual Studio solution in the given repository");
help.AddPostOptionsLine(" grr open Repo *.sln \tOpens the Visual Studio solutions in the given repository");
help.AddPostOptionsLine("");
help.AddPostOptionsLine("Use RegEx patterns for advanced filtering:");
help.AddPostOptionsLine("RegEx patterns for advanced repository filtering:");
help.AddPostOptionsLine(" grr list .*_.* \tLists all repositories containing a \"_\"");
help.AddPostOptionsLine(" grr list \".*[X|Z]\" \tLists all repositories ending with \"X\" or \"Y\"");
help.AddPostOptionsLine(" grr list \".*[X|Z]\" \tLists all repositories ending with \"X\" or \"Z\"");
help.AddPostOptionsLine(" grr cd Re.* \t\tNavigates to the first repository starting with \"Re\"");
help.AddPostOptionsLine(" grr open .*Z *.sln \tOpens each Visual Studio solution in every repository ending with \"Z\"");
help.AddPostOptionsLine("");
help.AddPostOptionsLine("Advanced: grr defines indexes for found repositories. They can be used for the next execution:");
help.AddPostOptionsLine(" grr list :3 \t\tShows the branch and status of the repository on index 3");
help.AddPostOptionsLine(" grr open :1 *.sln \tOpens the Visual Studio solutions found in repository on index 1");
help.AddPostOptionsLine(" grr list :3 *.* -r \tLists all files of the repository on index 3 recursively");
help.AddPostOptionsLine(" grr cd :21 \t\tNavigates to the repository on index 21");
help.AddPostOptionsLine("");
help.AddPostOptionsLine("Advanced: grr defines indexes for found repositories.");
help.AddPostOptionsLine(" They can be used as shortcut for the next execution:");
help.AddPostOptionsLine(" grr list :3 \tShows the branch and status of the repository on index 3");
help.AddPostOptionsLine(" grr cd :21 \tNavigates to the repository on index 21");
help.AddPostOptionsLine(" grr cd - \tNavigates back to the last path grr was called from");
help.AddPostOptionsLine("Bonus:");
help.AddPostOptionsLine(" grr cd - \t\tNavigates back to the last path grr was called from");
help.AddPostOptionsLine(" ");
help.AddPostOptionsLine("Noteworthy:");
help.AddPostOptionsLine(" The parameter \"list\" can be omitted, \"grr .*_.*\" has the same effect");
help.AddPostOptionsLine(" RepoZ has to be running on this system to use grr.");
help.AddPostOptionsLine("");


return help.ToString();
}

internal class FilterOptions
{
[ValueOption(0)]
public string RepositoryFilter { get; set; }

[ValueOption(1)]
public string FileFilter { get; set; }

}
}
}

0 comments on commit 7e07969

Please sign in to comment.