From a4bb8a8cb3119ae8f5f8861c2cf92566f453c945 Mon Sep 17 00:00:00 2001 From: leoporoli Date: Mon, 23 Oct 2023 15:24:42 -0300 Subject: [PATCH] refactor: update kurtosis package init cmd (#1588) ## Description: - package name is optional - remove flag - for validation errors, link docs + show an example ## Is this change user-facing? NO ## References (if applicable): --------- Co-authored-by: Gyanendra Mishra --- cli/cli/commands/package/init_cmd/init_cmd.go | 29 +++++++------------ docs/docs/cli-reference/package-init.md | 3 -- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/cli/cli/commands/package/init_cmd/init_cmd.go b/cli/cli/commands/package/init_cmd/init_cmd.go index 7adbdd6c49..c1493b94eb 100644 --- a/cli/cli/commands/package/init_cmd/init_cmd.go +++ b/cli/cli/commands/package/init_cmd/init_cmd.go @@ -8,20 +8,24 @@ import ( "github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel/flags" "github.com/kurtosis-tech/kurtosis/cli/cli/command_str_consts" "github.com/kurtosis-tech/kurtosis/cli/cli/kurtosis_package" + "github.com/kurtosis-tech/kurtosis/cli/cli/user_support_constants" "github.com/kurtosis-tech/stacktrace" "os" ) const ( packageNameArgKey = "package-name" - packageNameArgDefaultValue = "" - packageNameArgIsOptional = false + packageNameArgDefaultValue = "github.com/example-org/example-package" + packageNameArgIsOptional = true packageNameArgIsGreedy = false - executablePackageFlagKey = "main" - executablePackageFlagDefaultValue = "false" + alwaysCreateExecutablePackage = true + + validPackageNameExample = "github.com/kurtosis-tech/ethereum-package" ) +// InitCmd we only fill in the required struct fields, hence the others remain nil +// nolint: exhaustruct var InitCmd = &lowlevel.LowlevelKurtosisCommand{ CommandStr: command_str_consts.InitCmdStr, ShortDescription: "Creates a new Kurtosis package", @@ -35,14 +39,6 @@ var InitCmd = &lowlevel.LowlevelKurtosisCommand{ ValidationFunc: validatePackageNameArg, }, }, - Flags: []*flags.FlagConfig{ - { - Key: executablePackageFlagKey, - Usage: "indicates that the created package is an executable package, and generates a 'main.star' if one does not already exist.", - Type: flags.FlagType_Bool, - Default: executablePackageFlagDefaultValue, - }, - }, PreValidationAndRunFunc: nil, RunFunc: run, PostValidationAndRunFunc: nil, @@ -54,17 +50,12 @@ func run(ctx context.Context, flags *flags.ParsedFlags, args *args.ParsedArgs) e return stacktrace.Propagate(err, "an error occurred getting the value of argument with key '%v'", packageNameArgKey) } - executablePackageFlag, err := flags.GetBool(executablePackageFlagKey) - if err != nil { - return stacktrace.Propagate(err, "an error occurred getting the value of flag '%v'", executablePackageFlagKey) - } - packageDestinationDirpath, err := os.Getwd() if err != nil { return stacktrace.Propagate(err, "An error occurred getting the current working directory for creating the Kurtosis package") } - if err := kurtosis_package.InitializeKurtosisPackage(packageDestinationDirpath, packageNameArg, executablePackageFlag); err != nil { + if err := kurtosis_package.InitializeKurtosisPackage(packageDestinationDirpath, packageNameArg, alwaysCreateExecutablePackage); err != nil { return stacktrace.Propagate(err, "An error occurred initializing the Kurtosis package '%s' in '%s'", packageNameArg, packageDestinationDirpath) } @@ -78,7 +69,7 @@ func validatePackageNameArg(_ context.Context, _ *flags.ParsedFlags, args *args. } if _, err := shared_utils.ParseGitURL(packageNameArg); err != nil { - return stacktrace.Propagate(err, "An erro occurred validating package name '%v', invalid GitHub URL", packageNameArg) + return stacktrace.Propagate(err, "An error occurred validating package name '%v', invalid GitHub URL, the package name has to be a valid GitHub URL like '%s'. You can see more here: '%s' ", packageNameArg, validPackageNameExample, user_support_constants.StarlarkPackagesReferenceURL) } return nil diff --git a/docs/docs/cli-reference/package-init.md b/docs/docs/cli-reference/package-init.md index eab35e63cd..cd19daa9c8 100644 --- a/docs/docs/cli-reference/package-init.md +++ b/docs/docs/cli-reference/package-init.md @@ -8,9 +8,6 @@ Usage: The `package_name` argument is the [locator][locators]to the package, in the format `github.com/USER/REPO`. -This command accepts the following flags: -- `--main`: indicates that the created package is an [executable package][executable-package], and generates a `main.star` if one does not already exist. If a `main.star` already exists, does nothing. - [package]: ../concepts-reference/packages.md [kurtosis-yml]: ../concepts-reference/kurtosis-yml.md [locators]: ../concepts-reference/locators.md