MCPcopy
hub / github.com/git-lfs/git-lfs / Run

Function Run

commands/run.go:59–161  ·  view source on GitHub ↗

Run initializes the 'git-lfs' command and runs it with the given stdin and command line args. It returns an exit code.

()

Source from the content-addressed store, hash-verified

57//
58// It returns an exit code.
59func Run() int {
60 log.SetOutput(ErrorWriter)
61 tr.InitializeLocale()
62
63 root := NewCommand("git-lfs", gitlfsCommand)
64 root.PreRun = nil
65
66 completionCmd := &cobra.Command{
67 Use: "completion [bash|fish|zsh]",
68 DisableFlagsInUseLine: true,
69 ValidArgs: []string{"bash", "fish", "zsh"},
70 Args: cobra.MatchAll(cobra.ExactArgs(1), cobra.OnlyValidArgs),
71 Run: func(cmd *cobra.Command, args []string) {
72 switch args[0] {
73 case "bash":
74 completion := new(bytes.Buffer)
75 cmd.Root().GenBashCompletionV2(completion, false)
76
77 // this is needed for git bash completion to pick up the completion for the subcommand
78 completionSource := []byte(` local out directive
79 __git-lfs_get_completion_results
80`)
81 completionReplace := []byte(` if [[ ${words[0]} == "git" && ${words[1]} == "lfs" ]]; then
82 words=("git-lfs" "${words[@]:2:${#words[@]}-2}")
83 __git-lfs_debug "Rewritten words[*]: ${words[*]},"
84 fi
85
86 local out directive
87 __git-lfs_get_completion_results
88`)
89 newCompletion := bytes.NewBuffer(bytes.Replace(completion.Bytes(), completionSource, completionReplace, 1))
90 newCompletion.WriteString("_git_lfs() { __start_git-lfs; }\n")
91
92 newCompletion.WriteTo(os.Stdout)
93 case "fish":
94 cmd.Root().GenFishCompletion(os.Stdout, false)
95 case "zsh":
96 completion := new(bytes.Buffer)
97 cmd.Root().GenZshCompletionNoDesc(completion)
98
99 // this is needed for git zsh completion to use the right command for completion
100 completionSource := []byte(` requestComp="${words[1]} __completeNoDesc ${words[2,-1]}"`)
101 completionReplace := []byte(` requestComp="git-${words[1]#*git-} __completeNoDesc ${words[2,-1]}"`)
102 newCompletion := bytes.NewBuffer(bytes.Replace(completion.Bytes(), completionSource, completionReplace, 1))
103
104 newCompletion.WriteTo(os.Stdout)
105 }
106 },
107 }
108
109 root.AddCommand(completionCmd)
110
111 // Set up help/usage funcs based on manpage text
112 helpcmd := &cobra.Command{
113 Use: "help [command]",
114 Short: "Help about any command",
115 Long: `Help provides help for any command in the application.
116Simply type ` + root.Name() + ` help [path to command] for full details.`,

Callers 1

mainFunction · 0.92

Calls 8

InitializeLocaleFunction · 0.92
NewFunction · 0.92
NewCommandFunction · 0.85
canonicalizeEnvironmentFunction · 0.85
closeAPIClientFunction · 0.85
FindMethod · 0.80
NameMethod · 0.65
GetMethod · 0.65

Tested by

no test coverage detected