package commands import ( "fmt" "os" "strings" "github.com/github/git-lfs/config" "github.com/github/git-lfs/httputil" "github.com/spf13/cobra" ) func Run() { cfg = config.Config root := NewCommand("git-lfs", gitlfsCommand) root.PreRun = nil // Set up help/usage funcs based on manpage text root.SetHelpTemplate("{{.UsageString}}") root.SetHelpFunc(helpCommand) root.SetUsageFunc(usageCommand) for _, f := range commandFuncs { if cmd := f(); cmd != nil { root.AddCommand(cmd) } } root.Execute() httputil.LogHttpStats(cfg) } func gitlfsCommand(cmd *cobra.Command, args []string) { versionCommand(cmd, args) cmd.Usage() } func helpCommand(cmd *cobra.Command, args []string) { if len(args) == 0 { printHelp("git-lfs") } else { printHelp(args[0]) } } func usageCommand(cmd *cobra.Command) error { printHelp(cmd.Name()) return nil } func printHelp(commandName string) { if txt, ok := ManPages[commandName]; ok { fmt.Fprintf(os.Stderr, "%s\n", strings.TrimSpace(txt)) } else { fmt.Fprintf(os.Stderr, "Sorry, no usage text found for %q\n", commandName) } }