github.com/abdfnx/gh-api@v0.0.0-20210414084727-f5432eec23b8/pkg/cmd/root/help_topic.go (about)

     1  package root
     2  
     3  import (
     4  	"github.com/MakeNowJust/heredoc"
     5  	"github.com/spf13/cobra"
     6  )
     7  
     8  var HelpTopics = map[string]map[string]string{
     9  	"environment": {
    10  		"short": "Environment variables that can be used with gh",
    11  		"long": heredoc.Doc(`
    12  			GH_TOKEN, GITHUB_TOKEN (in order of precedence): an authentication token for github.com
    13  			API requests. Setting this avoids being prompted to authenticate and takes precedence over
    14  			previously stored credentials.
    15  
    16  			GH_ENTERPRISE_TOKEN, GITHUB_ENTERPRISE_TOKEN (in order of precedence): an authentication
    17  			token for API requests to GitHub Enterprise.
    18  
    19  			GH_REPO: specify the GitHub repository in the "[HOST/]OWNER/REPO" format for commands
    20  			that otherwise operate on a local repository.
    21  
    22  			GH_HOST: specify the GitHub hostname for commands that would otherwise assume
    23  			the "github.com" host when not in a context of an existing repository.
    24  
    25  			GH_EDITOR, GIT_EDITOR, VISUAL, EDITOR (in order of precedence): the editor tool to use
    26  			for authoring text.
    27  
    28  			BROWSER: the web browser to use for opening links.
    29  
    30  			DEBUG: set to any value to enable verbose output to standard error. Include values "api"
    31  			or "oauth" to print detailed information about HTTP requests or authentication flow.
    32  
    33  			GH_PAGER, PAGER (in order of precedence): a terminal paging program to send standard output to, e.g. "less".
    34  
    35  			GLAMOUR_STYLE: the style to use for rendering Markdown. See
    36  			https://github.com/charmbracelet/glamour#styles
    37  
    38  			NO_COLOR: set to any value to avoid printing ANSI escape sequences for color output.
    39  
    40  			CLICOLOR: set to "0" to disable printing ANSI colors in output.
    41  
    42  			CLICOLOR_FORCE: set to a value other than "0" to keep ANSI colors in output
    43  			even when the output is piped.
    44  
    45  			GH_NO_UPDATE_NOTIFIER: set to any value to disable update notifications. By default, gh
    46  			checks for new releases once every 24 hours and displays an upgrade notice on standard
    47  			error if a newer version was found.
    48  		`),
    49  	},
    50  	"reference": {
    51  		"short": "A comprehensive reference of all gh commands",
    52  	},
    53  }
    54  
    55  func NewHelpTopic(topic string) *cobra.Command {
    56  	cmd := &cobra.Command{
    57  		Use:    topic,
    58  		Short:  HelpTopics[topic]["short"],
    59  		Long:   HelpTopics[topic]["long"],
    60  		Hidden: true,
    61  		Annotations: map[string]string{
    62  			"markdown:generate": "true",
    63  			"markdown:basename": "gh_help_" + topic,
    64  		},
    65  	}
    66  
    67  	cmd.SetHelpFunc(helpTopicHelpFunc)
    68  	cmd.SetUsageFunc(helpTopicUsageFunc)
    69  
    70  	return cmd
    71  }
    72  
    73  func helpTopicHelpFunc(command *cobra.Command, args []string) {
    74  	command.Print(command.Long)
    75  }
    76  
    77  func helpTopicUsageFunc(command *cobra.Command) error {
    78  	command.Printf("Usage: gh help %s", command.Use)
    79  	return nil
    80  }