Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(CLI): Add category and refine help text #707

Merged
merged 2 commits into from
Aug 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 30 additions & 4 deletions pkg/app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,23 +37,26 @@ func New() EnvdApp {
internalApp.EnableBashCompletion = true
internalApp.Name = "envd"
internalApp.Usage = "Development environment for data science and AI/ML teams"
internalApp.HideHelpCommand = true
internalApp.HideVersion = true
internalApp.Version = version.GetVersion().String()
internalApp.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "debug",
Usage: "enable debug output in logs",
},
&cli.StringFlag{
Name: flag.FlagBuildkitdImage,
Usage: "docker image to use for buildkitd",
Value: "docker.io/moby/buildkit:v0.10.3",
Name: flag.FlagBuildkitdImage,
Usage: "docker image to use for buildkitd",
Value: "docker.io/moby/buildkit:v0.10.3",
Hidden: true,
},
}

internalApp.Commands = []*cli.Command{
CommandBootstrap,
CommandBuild,
CommandContext,
CommandBuild,
CommandDestroy,
CommandEnvironment,
CommandImage,
Expand All @@ -66,6 +69,29 @@ func New() EnvdApp {
CommandVersion,
}

internalApp.CustomAppHelpTemplate = ` envd - Development environment for data science and AI/ML teams

Usage:
envd up --path <path>

envd run --name <env-name> --command "pip list"{{if .VisibleCommands}}

Build and launch envd environments. Get more information at: https://envd.tensorchord.ai/.
To get started with using envd, check out the getting started guide: https://envd.tensorchord.ai/guide/getting-started.html.
{{range .VisibleCategories}}{{if .Name}}
{{.Name}}:{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{else}}{{range .VisibleCommands}}
{{join .Names ", "}}{{"\t"}}{{.Usage}}{{end}}{{end}}{{end}}{{end}}{{if .VisibleFlagCategories}}

Global Options:{{range .VisibleFlagCategories}}
{{if .Name}}{{.Name}}
{{end}}{{range .Flags}}{{.}}
{{end}}{{end}}{{else}}{{if .VisibleFlags}}

Global Options:
{{range $index, $option := .VisibleFlags}}{{if $index}}
{{end}}{{wrap $option.String 6}}{{end}}{{end}}{{end}}`

// Deal with debug flag.
var debugEnabled bool

Expand Down
5 changes: 3 additions & 2 deletions pkg/app/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@ import (
)

var CommandBootstrap = &cli.Command{
Name: "bootstrap",
Usage: "Bootstrap the envd installation including shell autocompletion and buildkit image download",
Name: "bootstrap",
Category: CategoryManagement,
Usage: "Bootstrap the envd installation",
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "buildkit",
Expand Down
18 changes: 8 additions & 10 deletions pkg/app/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,20 @@ import (

"github.com/cockroachdb/errors"
"github.com/sirupsen/logrus"
"github.com/spf13/viper"
"github.com/urfave/cli/v2"

"github.com/tensorchord/envd/pkg/builder"
"github.com/tensorchord/envd/pkg/docker"
"github.com/tensorchord/envd/pkg/flag"
"github.com/tensorchord/envd/pkg/home"
sshconfig "github.com/tensorchord/envd/pkg/ssh/config"
"github.com/tensorchord/envd/pkg/util/fileutil"
)

var CommandBuild = &cli.Command{
Name: "build",
Aliases: []string{"b"},
Usage: "Build the envd environment",
Name: "build",
Category: CategoryBasic,
Aliases: []string{"b"},
Usage: "Build the envd environment",
Description: `
To build an image using build.envd:
$ envd build
Expand Down Expand Up @@ -123,11 +122,10 @@ func build(clicontext *cli.Context) error {
}

logger := logrus.WithFields(logrus.Fields{
"build-context": buildContext,
"build-file": manifest,
"config": cfg,
"tag": tag,
flag.FlagBuildkitdImage: viper.GetString(flag.FlagBuildkitdImage),
"build-context": buildContext,
"build-file": manifest,
"config": cfg,
"tag": tag,
})
debug := clicontext.Bool("debug")
output := clicontext.String("output")
Expand Down
22 changes: 22 additions & 0 deletions pkg/app/const.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright 2022 The envd Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package app

const (
CategoryBasic = "Basic Commands"
CategoryManagement = "Management Commands"
CategoryAdvanced = "Advanced Commands"
CategoryOther = "Other Commands"
)
5 changes: 3 additions & 2 deletions pkg/app/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ import (
)

var CommandContext = &cli.Command{
Name: "context",
Usage: "Manage envd contexts",
Name: "context",
Category: CategoryManagement,
Usage: "Manage envd contexts",
Subcommands: []*cli.Command{
CommandContextCreate,
CommandContextList,
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/destroy.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,10 @@ import (
)

var CommandDestroy = &cli.Command{
Name: "destroy",
Aliases: []string{"d"},
Usage: "Destroy the envd environment",
Name: "destroy",
Category: CategoryBasic,
Aliases: []string{"d"},
Usage: "Destroy the envd environment",
Flags: []cli.Flag{
&cli.PathFlag{
Name: "path",
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import (
)

var CommandEnvironment = &cli.Command{
Name: "envs",
Aliases: []string{"env", "e"},
Usage: "Manage envd environments",
Name: "envs",
Category: CategoryBasic,
Aliases: []string{"env", "e"},
Usage: "Manage envd environments",

Subcommands: []*cli.Command{
CommandDescribeEnvironment,
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ import (
)

var CommandImage = &cli.Command{
Name: "images",
Aliases: []string{"image", "i"},
Usage: "Manage envd images",
Name: "images",
Category: CategoryBasic,
Aliases: []string{"image", "i"},
Usage: "Manage envd images",

Subcommands: []*cli.Command{
CommandDescribeImage,
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,10 @@ import (
var templatef embed.FS

var CommandInit = &cli.Command{
Name: "init",
Aliases: []string{"i"},
Usage: "Initializes the current directory with the build.envd file",
Name: "init",
Category: CategoryManagement,
Aliases: []string{"i"},
Usage: "Initializes the current directory with the build.envd file",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "lang",
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
)

var CommandPause = &cli.Command{
Name: "pause",
Aliases: []string{"p"},
Usage: "Pause the envd environment",
Name: "pause",
Category: CategoryAdvanced,
Aliases: []string{"p"},
Usage: "Pause the envd environment",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "env",
Expand Down
5 changes: 3 additions & 2 deletions pkg/app/prune.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ import (
)

var CommandPrune = &cli.Command{
Name: "prune",
Usage: "Clean up the build cache",
Name: "prune",
Category: CategoryManagement,
Usage: "Clean up the build cache",
Flags: []cli.Flag{
&cli.DurationFlag{
Name: "keep-duration",
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ import (
)

var CommandResume = &cli.Command{
Name: "resume",
Aliases: []string{"r"},
Usage: "Resume the envd environment",
Name: "resume",
Category: CategoryAdvanced,
Aliases: []string{"r"},
Usage: "Resume the envd environment",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "env",
Expand Down
5 changes: 3 additions & 2 deletions pkg/app/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (
)

var CommandRun = &cli.Command{
Name: "run",
Usage: "Spawns a command installed into the environment.",
Name: "run",
Category: CategoryBasic,
Usage: "Spawns a command installed into the environment.",
Flags: []cli.Flag{
&cli.PathFlag{
Name: "name",
Expand Down
7 changes: 4 additions & 3 deletions pkg/app/up.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,10 @@ const (
)

var CommandUp = &cli.Command{
Name: "up",
Aliases: []string{"u"},
Usage: "Build and run the envd environment",
Name: "up",
Category: CategoryBasic,
Aliases: []string{"u"},
Usage: "Build and run the envd environment",
Flags: []cli.Flag{
&cli.StringFlag{
Name: "tag",
Expand Down
9 changes: 5 additions & 4 deletions pkg/app/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,11 @@ import (
)

var CommandVersion = &cli.Command{
Name: "version",
Aliases: []string{"v"},
Usage: "Print envd version information",
Action: printVersion,
Name: "version",
Category: CategoryOther,
Aliases: []string{"v"},
Usage: "Print envd version information",
Action: printVersion,
Flags: []cli.Flag{
&cli.BoolFlag{
Name: "short",
Expand Down