-
Notifications
You must be signed in to change notification settings - Fork 687
Expand file tree
/
Copy pathroot.go
More file actions
70 lines (62 loc) · 2.08 KB
/
root.go
File metadata and controls
70 lines (62 loc) · 2.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package cli
import (
"fmt"
"os"
"github.com/spf13/cobra"
"github.com/replicate/cog/pkg/global"
"github.com/replicate/cog/pkg/update"
"github.com/replicate/cog/pkg/util/console"
)
func NewRootCommand() (*cobra.Command, error) {
rootCmd := cobra.Command{
Use: "cog",
Short: "Cog: Containers for machine learning",
Long: `Containers for machine learning.
To get started, take a look at the documentation:
https://github.com/replicate/cog`,
Example: ` To run a command inside a Docker environment defined with Cog:
$ cog run echo hello world`,
Version: fmt.Sprintf("%s (built %s)", global.Version, global.BuildTime),
// This stops errors being printed because we print them in cmd/cog/cog.go
PersistentPreRun: func(cmd *cobra.Command, args []string) {
if global.Debug {
console.SetLevel(console.DebugLevel)
}
if global.NoColor || !console.ShouldUseColor() {
console.SetColor(false)
}
if global.NoColor {
os.Setenv("NO_COLOR", "1") //nolint:errcheck,gosec // best-effort
}
cmd.SilenceUsage = true
if err := update.DisplayAndCheckForRelease(cmd.Context()); err != nil {
console.Debugf("%s", err)
}
},
SilenceErrors: true,
}
setPersistentFlags(&rootCmd)
rootCmd.AddCommand(
newBuildCommand(),
newDebugCommand(),
newInitCommand(),
newInspectCommand(),
newLoginCommand(),
newPredictCommand(),
newPushCommand(),
newRunCommand(),
newServeCommand(),
newTrainCommand(),
newWeightsCommand(),
)
return &rootCmd, nil
}
func setPersistentFlags(cmd *cobra.Command) {
cmd.PersistentFlags().BoolVar(&global.Debug, "debug", false, "Show debugging output")
cmd.PersistentFlags().BoolVar(&global.NoColor, "no-color", false, "Disable colored output")
cmd.PersistentFlags().BoolVar(&global.ProfilingEnabled, "profile", false, "Enable profiling")
cmd.PersistentFlags().Bool("version", false, "Show version of Cog")
cmd.PersistentFlags().StringVar(&global.ReplicateRegistryHost, "registry", global.ReplicateRegistryHost, "Registry host")
_ = cmd.PersistentFlags().MarkHidden("profile")
_ = cmd.PersistentFlags().MarkHidden("registry")
}