Skip to content

Commit d2f10d2

Browse files
authored
Misc UI improvements (#1159)
1 parent 7a4ac70 commit d2f10d2

File tree

10 files changed

+50
-6
lines changed

10 files changed

+50
-6
lines changed

cli/cmd/completion.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ to enable cortex shell completion:
7575
7676
Note: this will also add the "cx" alias for cortex for convenience
7777
`,
78-
Args: cobra.ExactArgs(1),
78+
Args: cobra.ExactArgs(1),
79+
ValidArgs: []string{"bash", "zsh"},
7980
Run: func(cmd *cobra.Command, args []string) {
8081
switch args[0] {
8182
case "bash":

cli/cmd/deploy.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,15 @@ var _deployCmd = &cobra.Command{
7474
}
7575

7676
configPath := getConfigPath(args)
77+
78+
deployDir := s.EnsureSuffix(filepath.Dir(files.UserRelToAbsPath(configPath)), "/")
79+
if deployDir == _homeDir {
80+
exit.Error(ErrorDeployFromTopLevelDir("home", env.Provider))
81+
}
82+
if deployDir == "/" {
83+
exit.Error(ErrorDeployFromTopLevelDir("root", env.Provider))
84+
}
85+
7786
var deployResponse schema.DeployResponse
7887
if env.Provider == types.AWSProviderType {
7988
deploymentBytes, err := getDeploymentBytes(env.Provider, configPath)

cli/cmd/errors.go

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"runtime"
2323
"strings"
2424

25+
"github.com/cortexlabs/cortex/pkg/consts"
2526
"github.com/cortexlabs/cortex/pkg/lib/errors"
2627
s "github.com/cortexlabs/cortex/pkg/lib/strings"
2728
"github.com/cortexlabs/cortex/pkg/lib/urls"
@@ -76,6 +77,8 @@ const (
7677
ErrClusterConfigOrPromptsRequired = "cli.cluster_config_or_prompts_required"
7778
ErrClusterAccessConfigOrPromptsRequired = "cli.cluster_access_config_or_prompts_required"
7879
ErrShellCompletionNotSupported = "cli.shell_completion_not_supported"
80+
ErrNoTerminalWidth = "cli.no_terminal_width"
81+
ErrDeployFromTopLevelDir = "cli.deploy_from_top_level_dir"
7982
)
8083

8184
func ErrorInvalidProvider(providerStr string) error {
@@ -317,6 +320,24 @@ func ErrorClusterAccessConfigOrPromptsRequired() error {
317320
func ErrorShellCompletionNotSupported(shell string) error {
318321
return errors.WithStack(&errors.Error{
319322
Kind: ErrShellCompletionNotSupported,
320-
Message: fmt.Sprintf("shell completion for %s is not supported", shell),
323+
Message: fmt.Sprintf("shell completion for %s is not supported (only bash and zsh are supported)", shell),
324+
})
325+
}
326+
327+
func ErrorNoTerminalWidth() error {
328+
return errors.WithStack(&errors.Error{
329+
Kind: ErrNoTerminalWidth,
330+
Message: "unable to determine terminal width; please re-run the command without the `--watch` flag",
331+
})
332+
}
333+
334+
func ErrorDeployFromTopLevelDir(genericDirName string, providerType types.ProviderType) error {
335+
targetStr := "cluster"
336+
if providerType == types.LocalProviderType {
337+
targetStr = "API container"
338+
}
339+
return errors.WithStack(&errors.Error{
340+
Kind: ErrDeployFromTopLevelDir,
341+
Message: fmt.Sprintf("cannot deploy from your %s directory - when deploying your API, cortex sends all files in your project directory (i.e. the directory which contains cortex.yaml) to your %s (see https://docs.cortex.dev/v/%s/deployments/predictors#project-files); therefore it is recommended to create a subdirectory for your project files", genericDirName, targetStr, consts.CortexVersionMinor),
321342
})
322343
}

cli/cmd/lib_cluster_config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func getInstallClusterConfig(awsCreds AWSCredentials, envName string, disallowPr
169169

170170
err = clusterConfig.Validate(awsClient)
171171
if err != nil {
172+
err = errors.Append(err, fmt.Sprintf("\n\ncluster configuration schema can be found here: https://docs.cortex.dev/v/%s/cluster-management/config", consts.CortexVersionMinor))
172173
if _flagClusterConfig != "" {
173174
err = errors.Wrap(err, _flagClusterConfig)
174175
}
@@ -234,6 +235,7 @@ func getConfigureClusterConfig(cachedClusterConfig clusterconfig.Config, awsCred
234235

235236
err = userClusterConfig.Validate(awsClient)
236237
if err != nil {
238+
err = errors.Append(err, fmt.Sprintf("\n\ncluster configuration schema can be found here: https://docs.cortex.dev/v/%s/cluster-management/config", consts.CortexVersionMinor))
237239
if _flagClusterConfig != "" {
238240
err = errors.Wrap(err, _flagClusterConfig)
239241
}

cli/cmd/lib_watch.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,9 @@ func rerun(f func() (string, error)) {
7373
nextStrSlice := strings.Split(nextStr, "\n")
7474

7575
terminalWidth := getTerminalWidth()
76+
if terminalWidth <= 0 {
77+
exit.Error(ErrorNoTerminalWidth())
78+
}
7679

7780
nextNumLines := 0
7881
for _, strLine := range nextStrSlice {

cli/cmd/root.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ var (
4141
_emailPath string
4242
_debugPath string
4343
_cwd string
44+
_homeDir string
4445
)
4546

4647
type commandType int
@@ -63,6 +64,7 @@ func init() {
6364
err := errors.Wrap(err, "unable to determine home directory")
6465
exit.Error(err)
6566
}
67+
_homeDir = s.EnsureSuffix(homeDir, "/")
6668

6769
_localDir = filepath.Join(homeDir, ".cortex")
6870
err = os.MkdirAll(_localDir, os.ModePerm)

cli/local/deploy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ limitations under the License.
1717
package local
1818

1919
import (
20+
"fmt"
2021
"path/filepath"
2122

2223
"github.com/cortexlabs/cortex/cli/types/cliconfig"
24+
"github.com/cortexlabs/cortex/pkg/consts"
2325
"github.com/cortexlabs/cortex/pkg/lib/aws"
2426
"github.com/cortexlabs/cortex/pkg/lib/docker"
2527
"github.com/cortexlabs/cortex/pkg/lib/errors"
@@ -65,6 +67,7 @@ func Deploy(env cliconfig.Environment, absoluteConfigPath string, projectFileLis
6567

6668
err = ValidateLocalAPIs(apiConfigs, projectFiles, awsClient)
6769
if err != nil {
70+
err = errors.Append(err, fmt.Sprintf("\n\napi configuration schema can be found here: https://docs.cortex.dev/v/%s/deployments/api-configuration", consts.CortexVersionMinor))
6871
return schema.DeployResponse{}, err
6972
}
7073

pkg/operator/endpoints/deploy.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@ limitations under the License.
1717
package endpoints
1818

1919
import (
20+
"fmt"
2021
"net/http"
2122

23+
"github.com/cortexlabs/cortex/pkg/consts"
2224
"github.com/cortexlabs/cortex/pkg/lib/errors"
2325
"github.com/cortexlabs/cortex/pkg/lib/files"
2426
"github.com/cortexlabs/cortex/pkg/lib/hash"
@@ -73,6 +75,7 @@ func Deploy(w http.ResponseWriter, r *http.Request) {
7375

7476
err = operator.ValidateClusterAPIs(apiConfigs, projectFiles)
7577
if err != nil {
78+
err = errors.Append(err, fmt.Sprintf("\n\napi configuration schema can be found here: https://docs.cortex.dev/v/%s/deployments/api-configuration", consts.CortexVersionMinor))
7679
respondError(w, r, err)
7780
return
7881
}

pkg/operator/endpoints/errors.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func ErrorAuthInvalid() error {
7575
func ErrorAuthOtherAccount() error {
7676
return errors.WithStack(&errors.Error{
7777
Kind: ErrAuthOtherAccount,
78-
Message: "AWS account associated with CLI AWS credentials differs from account associated with cluster AWS credentials; run `cortex env configure` to configure your environment with credentials for any IAM user in the same AWS account as your cluster",
78+
Message: "the AWS account associated with your CLI's AWS credentials differs from the AWS account associated with your cluster's AWS credentials; run `cortex env configure` to configure your environment with credentials for any IAM user in the same AWS account as your cluster",
7979
})
8080
}
8181

pkg/types/clusterconfig/errors.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,10 @@ func ErrorIncompatibleSpotInstanceTypeInf(suggested aws.InstanceMetadata) error
112112
})
113113
}
114114

115-
func ErrorSpotPriceGreaterThanTargetOnDemand(suggestedSpotPrice float64, target aws.InstanceMetadata, suggested aws.InstanceMetadata) error {
115+
func ErrorSpotPriceGreaterThanTargetOnDemand(spotPrice float64, target aws.InstanceMetadata, suggested aws.InstanceMetadata) error {
116116
return errors.WithStack(&errors.Error{
117117
Kind: ErrSpotPriceGreaterThanTargetOnDemand,
118-
Message: fmt.Sprintf("%s will not be allocated because its current spot price is $%g which is greater than %s's on-demand price of $%g", suggested.Type, suggestedSpotPrice, target.Type, target.Price),
118+
Message: fmt.Sprintf("%s will not be allocated because its current spot price is $%g which is greater than %s's on-demand price of $%g", suggested.Type, spotPrice, target.Type, target.Price),
119119
})
120120
}
121121

@@ -136,7 +136,7 @@ func ErrorInstanceTypeNotSupported(instanceType string) error {
136136
func ErrorConfiguredWhenSpotIsNotEnabled(configKey string) error {
137137
return errors.WithStack(&errors.Error{
138138
Kind: ErrConfiguredWhenSpotIsNotEnabled,
139-
Message: fmt.Sprintf("%s cannot be specified unless spot is enabled", configKey),
139+
Message: fmt.Sprintf("%s cannot be specified unless spot is enabled (to enable spot instances, set `%s: true` in your cluster configuration file)", configKey, SpotKey),
140140
})
141141
}
142142

0 commit comments

Comments
 (0)