github.com/pengwynn/gh@v1.0.1-0.20140118055701-14327ca3942e/commands/help.go (about)

     1  package commands
     2  
     3  import (
     4  	"fmt"
     5  	"os"
     6  	"strings"
     7  )
     8  
     9  var cmdHelp = &Command{
    10  	Usage:        "help [command]",
    11  	Short:        "Show help",
    12  	Long:         `Shows usage for a command.`,
    13  	GitExtension: true,
    14  }
    15  
    16  var (
    17  	customCommands = []string{
    18  		"alias",
    19  		"create",
    20  		"browse",
    21  		"compare",
    22  		"fork",
    23  		"pull-request",
    24  		"ci-status",
    25  		"release",
    26  		"issue",
    27  		"update",
    28  	}
    29  )
    30  
    31  func init() {
    32  	cmdHelp.Run = runHelp
    33  
    34  	CmdRunner.Use(cmdHelp)
    35  }
    36  
    37  func runHelp(cmd *Command, args *Args) {
    38  	if args.IsParamsEmpty() {
    39  		printUsage()
    40  		os.Exit(0)
    41  	}
    42  
    43  	for _, cmd := range CmdRunner.All() {
    44  		if cmd.Name() == args.FirstParam() {
    45  			cmd.PrintUsage()
    46  			os.Exit(0)
    47  		}
    48  	}
    49  
    50  	if parseHelpAllFlag(args) {
    51  		args.After("echo", "\ngh custom commands\n")
    52  		args.After("echo", " ", strings.Join(customCommands, "  "))
    53  	}
    54  }
    55  
    56  func parseHelpAllFlag(args *Args) bool {
    57  	i := args.IndexOfParam("-a")
    58  	if i != -1 {
    59  		return true
    60  	}
    61  
    62  	i = args.IndexOfParam("--all")
    63  	if i != -1 {
    64  		return true
    65  	}
    66  
    67  	return false
    68  }
    69  
    70  var helpText = `usage: git [--version] [--exec-path[=<path>]] [--html-path] [--man-path] [--info-path]
    71             [-p|--paginate|--no-pager] [--no-replace-objects] [--bare]
    72             [--git-dir=<path>] [--work-tree=<path>] [--namespace=<name>]
    73             [-c name=value] [--help]
    74             <command> [<args>]
    75  
    76  Basic Commands:
    77     init       Create an empty git repository or reinitialize an existing one
    78     add        Add new or modified files to the staging area
    79     rm         Remove files from the working directory and staging area
    80     mv         Move or rename a file, a directory, or a symlink
    81     status     Show the status of the working directory and staging area
    82     commit     Record changes to the repository
    83  
    84  History Commands:
    85     log        Show the commit history log
    86     diff       Show changes between commits, commit and working tree, etc
    87     show       Show information about commits, tags or files
    88  
    89  Branching Commands:
    90     branch     List, create, or delete branches
    91     checkout   Switch the active branch to another branch
    92     merge      Join two or more development histories (branches) together
    93     tag        Create, list, delete, sign or verify a tag object
    94  
    95  Remote Commands:
    96     clone      Clone a remote repository into a new directory
    97     fetch      Download data, tags and branches from a remote repository
    98     pull       Fetch from and merge with another repository or a local branch
    99     push       Upload data, tags and branches to a remote repository
   100     remote     View and manage a set of remote repositories
   101  
   102  Advanced Commands:
   103     reset      Reset your staging area or working directory to another point
   104     rebase     Re-apply a series of patches in one branch onto another
   105     bisect     Find by binary search the change that introduced a bug
   106     grep       Print files with lines matching a pattern in your codebase
   107  
   108  GitHub Commands:
   109     pull-request   Open a pull request on GitHub
   110     fork           Make a fork of a remote repository on GitHub and add as remote
   111     create         Create this repository on GitHub and add GitHub as origin
   112     browse         Open a GitHub page in the default browser
   113     compare        Open a compare page on GitHub
   114     release        List or create releases (beta)
   115     issue          List or create issues (beta)
   116     ci-status      Show the CI status of a commit
   117  
   118  See 'git help <command>' for more information on a specific command.
   119  Run 'git update' to update to the latest version of gh.
   120  `
   121  
   122  func printUsage() {
   123  	fmt.Print(helpText)
   124  }