mirror of https://github.com/databricks/cli.git
exit code done
This commit is contained in:
parent
993956294a
commit
05cd18c0be
|
@ -7,3 +7,8 @@ hello, world
|
|||
|
||||
>>> [CLI] bundle exec -- echo --help
|
||||
--help
|
||||
|
||||
>>> [CLI] bundle exec -- bash -c exit 5
|
||||
Error: Running "bash -c exit 5" failed with exit code: 5
|
||||
|
||||
Exit code: 1
|
||||
|
|
|
@ -4,3 +4,6 @@ trace $CLI bundle exec -- pwd
|
|||
|
||||
# The CLI should not parse the --help flag and should pass it as is to echo.
|
||||
trace $CLI bundle exec -- echo --help
|
||||
|
||||
# The error message should include the exit code.
|
||||
trace $CLI bundle exec -- bash -c "exit 5"
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
>>> errcode [CLI] bundle exec -t pat -- databricks current-user me -t oauth
|
||||
Error: cannot resolve bundle auth configuration: validate: more than one authorization method configured: oauth and pat. Config: host=[DATABRICKS_URL], token=***, client_id=client_id, databricks_cli_path=[CLI]. Env: DATABRICKS_HOST, DATABRICKS_TOKEN, DATABRICKS_CLI_PATH
|
||||
Error: Command exited with code: 1
|
||||
Error: Running "databricks current-user me -t oauth" failed with exit code: 1
|
||||
|
||||
Exit code: 1
|
||||
|
||||
|
|
|
@ -13,6 +13,15 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
type exitCodeErr struct {
|
||||
exitCode int
|
||||
args []string
|
||||
}
|
||||
|
||||
func (e *exitCodeErr) Error() string {
|
||||
return fmt.Sprintf("Running %q failed with exit code: %d", strings.Join(e.args, " "), e.exitCode)
|
||||
}
|
||||
|
||||
func newExecCommand() *cobra.Command {
|
||||
execCmd := &cobra.Command{
|
||||
Use: "exec",
|
||||
|
@ -110,11 +119,16 @@ Examples:
|
|||
}()
|
||||
|
||||
// Wait for the command to finish.
|
||||
// TODO: Pretty exit codes?
|
||||
// TODO: Make CLI return the same exit codes? It has to, that's a requirement.
|
||||
err = childCmd.Wait()
|
||||
if exitErr, ok := err.(*exec.ExitError); ok {
|
||||
return fmt.Errorf("Command exited with code: %d", exitErr.ExitCode())
|
||||
// We don't propagate the exit code as is because exit codes for
|
||||
// the CLI have not been standardized yet. At some point in the
|
||||
// future we might want to associate specific exit codes with
|
||||
// specific classes of errors.
|
||||
return &exitCodeErr{
|
||||
exitCode: exitErr.ExitCode(),
|
||||
args: args,
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("Error waiting for command: %w", err)
|
||||
|
|
Loading…
Reference in New Issue