diff --git a/cli/cmd/chains/archway/run.go b/cli/cmd/chains/archway/run.go index bda0850e..43e7692e 100644 --- a/cli/cmd/chains/archway/run.go +++ b/cli/cmd/chains/archway/run.go @@ -28,7 +28,7 @@ func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) { return nil, common.WrapMessageToError(common.ErrDataMarshall, err.Error()) } - runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveArchwayDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName) + runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveCosmosDefaultNodeScript, runArchwayNodeWithDefaultConfigFunctionName) response, _, err := enclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, runConfig) @@ -45,7 +45,7 @@ func RunArchway(cli *common.Cli) (*common.DiveServiceResponse, error) { return nil, common.WrapMessageToError(errRemove, "Archway Run Failed.") } - return nil, common.WrapMessageToError(err, "Archway Run Failed. Services Removed ") + return nil, common.WrapMessageToErrorf(err, "%s. %s", err, "Archway Run Failed") } if cli.Context().CheckSkippedInstructions(skippedInstructions) { diff --git a/cli/cmd/chains/icon/run.go b/cli/cmd/chains/icon/run.go index 279fa784..ffe6f166 100644 --- a/cli/cmd/chains/icon/run.go +++ b/cli/cmd/chains/icon/run.go @@ -77,7 +77,7 @@ func RunDecentralization(cli *common.Cli, params string) error { if err != nil { return common.WrapMessageToError(err, "Icon Decentralization Failed") } - starlarkConfig := common.GetStarlarkRunConfig(params, common.DiveIconDecentraliseScript, "configure_node") + starlarkConfig := common.GetStarlarkRunConfig(params, common.DiveIconDecentralizeScript, "configure_node") data, _, err := kurtosisEnclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, starlarkConfig) if err != nil { diff --git a/cli/cmd/chains/neutron/run.go b/cli/cmd/chains/neutron/run.go index abf1eb8d..6f633470 100644 --- a/cli/cmd/chains/neutron/run.go +++ b/cli/cmd/chains/neutron/run.go @@ -29,7 +29,7 @@ func RunNeutron(cli *common.Cli) (*common.DiveServiceResponse, error) { return nil, common.WrapMessageToError(common.ErrDataMarshall, err.Error()) } - runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveNeutronDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName) + runConfig := common.GetStarlarkRunConfig(encodedServiceConfigDataString, common.DiveCosmosDefaultNodeScript, runNeutronNodeWithDefaultConfigFunctionName) response, _, err := enclaveContext.RunStarlarkRemotePackage(cli.Context().GetContext(), common.DiveRemotePackagePath, runConfig) diff --git a/cli/common/constants.go b/cli/common/constants.go index 7c68e4ea..50d56922 100644 --- a/cli/common/constants.go +++ b/cli/common/constants.go @@ -1,19 +1,16 @@ package common -var DiveLogs bool -var EnclaveName string - // !!!!!!!!!!! DO NOT UPDATE! WILL BE UPDATED DURING THE RELEASE PROCESS !!!!!!!!!!!!!!!!!!!!!! -var DiveVersion = "v0.0.14-beta" +const DiveVersion = "v0.0.14-beta" const ( DiveEnclave = "dive" - DiveRemotePackagePath = "github.com/hugobyte/dive" + DiveRemotePackagePath = "github.com/hugobyte/dive-packages" DiveIconNodeScript = "services/jvm/icon/src/node-setup/start_icon_node.star" - DiveIconDecentraliseScript = "services/jvm/icon/src/node-setup/setup_icon_node.star" + DiveIconDecentralizeScript = "services/jvm/icon/src/node-setup/setup_icon_node.star" DiveEthHardhatNodeScript = "services/evm/eth/src/node-setup/start-eth-node.star" DiveArchwayNodeScript = "services/cosmvm/archway/src/node-setup/start_node.star" - DiveArchwayDefaultNodeScript = "services/cosmvm/archway/archway.star" + DiveCosmosDefaultNodeScript = "services/cosmvm/cosmos_chains.star" DiveNeutronNodeScript = "services/cosmvm/neutron/src/node-setup/start_node.star" RelayServiceNameIconToCosmos = "ibc-relayer" DiveNeutronDefaultNodeScript = "services/cosmvm/neutron/neutron.star" @@ -21,18 +18,18 @@ const ( DiveBridgeIbcScript = "/services/bridges/ibc/src/bridge.star" DiveDryRun = false DiveDefaultParallelism = 4 - DiveEthNodeAlreadyRunning = "Eth Node Already Running" - DiveHardhatNodeAlreadyRuning = "Hardhat Node Already Running" - DiveIconNodeAlreadyRunning = "Icon Node Already Running" DiveLogDirectory = "/logs/" DiveDitLogFile = "dive.log" DiveErrorLogFile = "error.log" DiveOutFile = "dive_%s.json" ServiceFilePath = "services_%s.json" - starlarkScript = ` + removeServiceStarlarkScript = ` +def run(plan,args): + plan.remove_service(name=args["service_name"]) +` + stopServiceStarlarkScript = ` def run(plan, args): plan.stop_service(name=args["service_name"]) - plan.print(args["uuid"]) # we add this print of a random UUID to make sure the single stop_service above won't get cached ` ) @@ -80,3 +77,6 @@ const ( InvalidChain PortError ) + +var DiveLogs bool +var EnclaveName string diff --git a/cli/common/context.go b/cli/common/context.go index 1fcacb4e..88d289ed 100644 --- a/cli/common/context.go +++ b/cli/common/context.go @@ -11,18 +11,6 @@ import ( "github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" ) -const ( - removeServiceStarlarkScript = ` -def run(plan,args): - plan.remove_service(name=args["service_name"]) -` - - stopServiceStarlarkScript = ` -def run(plan, args): - plan.stop_service(name=args["service_name"]) -` -) - type diveContext struct { mu sync.Mutex ctx context.Context diff --git a/cli/common/interfaces.go b/cli/common/interfaces.go index 297612f0..82de3115 100644 --- a/cli/common/interfaces.go +++ b/cli/common/interfaces.go @@ -10,61 +10,158 @@ import ( "github.com/spf13/cobra" ) +// Logger represents a generic logging interface with various log levels and formatting options. type Logger interface { + // SetErrorToStderr configures the logger to output error messages to stderr. SetErrorToStderr() + + // SetOutputToStdout configures the logger to output messages to stdout. SetOutputToStdout() + + // Debug logs a debug message. Debug(message string) + + // Info logs an informational message. Info(message string) + + // Warn logs a warning message. Warn(message string) + + // Error logs an error with an error code and a corresponding error message. Error(errorCode ErrorCode, errorMessage string) + + // Fatal logs a fatal error with an error code and a corresponding error message, + // and then exits the program. Fatal(errorCode ErrorCode, errorMessage string) + + // Infof logs a formatted informational message. Infof(format string, args ...interface{}) + + // Warnf logs a formatted warning message. Warnf(format string, args ...interface{}) + + // Debugf logs a formatted debug message. Debugf(format string, args ...interface{}) + + // Errorf logs a formatted error with an error code and a corresponding error message. Errorf(errorCode ErrorCode, format string, args ...interface{}) + + // Fatalf logs a formatted fatal error with an error code and a corresponding error message, + // and then exits the program. Fatalf(errorCode ErrorCode, format string, args ...interface{}) } +// Spinner is an interface for managing and controlling a terminal spinner. type Spinner interface { + // SetSuffixMessage sets a suffix message to be displayed beside the spinner. SetSuffixMessage(message, color string) + + // SetPrefixMessage sets a prefix message to be displayed beside the spinner. SetPrefixMessage(message string) + + // SetColor sets the color of the spinner. SetColor(color string) + + // Start starts the spinner with the specified color. Start(color string) + + // StartWithMessage starts the spinner with a specified message and color. StartWithMessage(message, color string) + + // Stop stops the spinner. Stop() + + // StopWithMessage stops the spinner and displays a final message. StopWithMessage(message string) } +// Context represents a context for managing and interacting with enclaves and services. type Context interface { + // GetContext returns the underlying context.Context. GetContext() context.Context + + // GetKurtosisContext returns the Kurtosis context, including configuration and utility functions. GetKurtosisContext() (*kurtosis_context.KurtosisContext, error) + + // GetEnclaves retrieves information about all enclaves currently running. GetEnclaves() ([]EnclaveInfo, error) + + // GetEnclaveContext retrieves the context of a specific enclave by its name. GetEnclaveContext(enclaveName string) (*enclaves.EnclaveContext, error) + + // CleanEnclaves stops and cleans up all running enclaves. CleanEnclaves() ([]*EnclaveInfo, error) + + // CleanEnclaveByName stops and cleans up a specific enclave by its name. CleanEnclaveByName(enclaveName string) error + + // CheckSkippedInstructions checks if specific instructions are skipped in the current kurtosis run context. CheckSkippedInstructions(instructions map[string]bool) bool + + // StopService stops a specific service within an enclave by name. StopService(serviceName string, enclaveName string) error + + // StopServices stops all services within a specific enclave. StopServices(enclaveName string) error + + // RemoveServices stops and removes all services within a specific enclave. RemoveServices(enclaveName string) error + + // RemoveService stops and removes a specific service within an enclave by name. RemoveService(serviceName string, enclaveName string) error + + // RemoveServicesByServiceNames stops and removes services within an enclave based on a map of service names. RemoveServicesByServiceNames(services map[string]string, enclaveName string) error + + // CreateEnclave creates a new enclave with the specified name and returns its context. CreateEnclave(enclaveName string) (*enclaves.EnclaveContext, error) + + // Exit terminates the execution of the context with the given status code. Exit(statusCode int) } +// FileHandler defines methods for handling file-related operations. type FileHandler interface { + // ReadFile reads the contents of a file specified by the filePath. ReadFile(filePath string) ([]byte, error) + + // ReadJson reads the contents of a JSON file specified by the fileName + // and unmarshals it into the provided object (obj). ReadJson(fileName string, obj interface{}) error + + // ReadAppFile reads the contents of an application-specific file specified by the fileName. ReadAppFile(fileName string) ([]byte, error) + + // WriteFile writes the provided data to a file specified by the fileName. WriteFile(fileName string, data []byte) error + + // WriteJson writes the provided data, marshaled as JSON, to a file specified by the fileName. WriteJson(fileName string, data interface{}) error + + // WriteAppFile writes the provided data to an application-specific file specified by the fileName. WriteAppFile(fileName string, data []byte) error + + // GetPwd returns the current working directory. GetPwd() (string, error) + + // GetHomeDir returns the home directory of the user. GetHomeDir() (string, error) + + // MkdirAll creates a directory along with any necessary parents, + // and sets the specified permission. MkdirAll(dirPath string, permission fs.FileMode) error + + // OpenFile opens a file with the specified fileOpenMode and permission. OpenFile(filePath string, fileOpenMode string, permission int) (*os.File, error) + + // RemoveFile removes the file specified by the fileName. RemoveFile(fileName string) error + + // RemoveFiles removes multiple files specified by the fileNames. RemoveFiles(fileNames []string) error + + // GetAppDirPathOrAppFilePath returns the path to the application directory or a specific file within it + // based on the provided fileName. GetAppDirPathOrAppFilePath(fileName string) (string, error) } @@ -111,10 +208,18 @@ type CommandBuilder interface { // SetRun sets the Run field of the command. SetRun(run func(cmd *cobra.Command, args []string)) CommandBuilder + // ToggleHelpCommand enables or disables the automatic generation of a help command. ToggleHelpCommand(enable bool) CommandBuilder + // SetRunE sets the RunE field of the command. SetRunE(run func(cmd *cobra.Command, args []string) error) CommandBuilder + + // MarkFlagsAsRequired marks multiple flags as required for the command. MarkFlagsAsRequired(flags []string) CommandBuilder + + // MarkFlagRequired marks a flag as required for the command. MarkFlagRequired(flag string) CommandBuilder + + // AddBoolFlagP adds a boolean flag with shorthand to the command. AddBoolFlagP(name string, shorthand string, value bool, usage string) CommandBuilder } diff --git a/cli/common/logs.go b/cli/common/logs.go index 27f482df..0722b70d 100644 --- a/cli/common/logs.go +++ b/cli/common/logs.go @@ -10,10 +10,15 @@ import ( "github.com/sirupsen/logrus" ) +// The diveLogger type is a struct that contains a logrus.Logger instance. +// log - The `log` is a pointer to an instance of the `logrus.Logger` struct. This +// logger is used for logging messages and events in the `diveLogger` struct. type diveLogger struct { log *logrus.Logger } +// The function `NewDiveLogger` creates a new instance of a logger that logs information and errors to +// separate files. func NewDiveLogger(infoFilePath string, errorFilePath string) *diveLogger { log := logrus.New() @@ -60,57 +65,98 @@ func NewDiveLogger(infoFilePath string, errorFilePath string) *diveLogger { return &diveLogger{log: log} } +// The `SetErrorToStderr()` function sets the output of the logger to `os.Stderr`. This means that any +// log messages or errors logged using this logger will be printed to the standard error output. func (d *diveLogger) SetErrorToStderr() { d.log.SetOutput(os.Stderr) } + +// The `SetOutputToStdout()` function sets the output of the logger to `os.Stdout`. This means that any +// log messages or errors logged using this logger will be printed to the standard output. func (d *diveLogger) SetOutputToStdout() { d.log.SetOutput(os.Stdout) } +// The `logWithFields` function is a helper function in the `diveLogger` struct. It is used to log +// messages with additional fields. func (d *diveLogger) logWithFields(level logrus.Level, kind string, format string, args ...interface{}) { if d.log.IsLevelEnabled(level) { - d.log.WithFields(logrus.Fields{level.String(): kind}).Logf(level, format, args...) + formatWithKind := " " + kind + " " + format + d.log.Logf(level, formatWithKind, args...) } } +// The `Debug` function is a method of the `diveLogger` struct. It is used to log a debug message with +// the specified message string. It calls the `logWithFields` function, passing the log level +// `logrus.DebugLevel`, the kind "🐞 debug", and the message string as arguments. The `logWithFields` +// function adds the log level and kind as fields to the log entry and logs the message using the +// logrus logger. func (d *diveLogger) Debug(message string) { d.logWithFields(logrus.DebugLevel, "🐞 debug", message) } +// The `Info` function is a method of the `diveLogger` struct. It is used to log an informational +// message with the specified message string. func (d *diveLogger) Info(message string) { d.logWithFields(logrus.InfoLevel, "ℹī¸", message) } +// The `Warn` function is a method of the `diveLogger` struct. It is used to log a warning message with +// the specified message string. func (d *diveLogger) Warn(message string) { d.logWithFields(logrus.WarnLevel, "⚠ī¸", message) } +// The `Error` function is a method of the `diveLogger` struct. It is used to log an error message with +// the specified error code and error message. func (d *diveLogger) Error(errorCode ErrorCode, errorMessage string) { d.logWithFields(logrus.ErrorLevel, "🛑", "Code:%d Error: %s", errorCode, errorMessage) } +// The `Fatal` function is a method of the `diveLogger` struct. It is used to log an error message with +// the specified error code and error message, and then exit the program with a status code of 1. func (d *diveLogger) Fatal(errorCode ErrorCode, errorMessage string) { d.logWithFields(logrus.FatalLevel, "💀", "Code:%d Error: %s", errorCode, errorMessage) d.log.Exit(1) } +// The `Infof` function is a method of the `diveLogger` struct. It is used to log an informational +// message with the specified format string and arguments. func (d *diveLogger) Infof(format string, args ...interface{}) { d.logWithFields(logrus.InfoLevel, "ℹī¸", format, args...) } +// The `Warnf` function is a method of the `diveLogger` struct. It is used to log a warning message +// with the specified format string and arguments. It calls the `logWithFields` function, passing the +// log level `logrus.WarnLevel`, the kind "⚠ī¸", and the format string and arguments as arguments. The +// `logWithFields` function adds the log level and kind as fields to the log entry and logs the +// formatted message using the logrus logger. func (d *diveLogger) Warnf(format string, args ...interface{}) { d.logWithFields(logrus.WarnLevel, "⚠ī¸", format, args...) } +// The `Debugf` function is a method of the `diveLogger` struct. It is used to log a debug message with +// the specified format string and arguments. It calls the `logWithFields` function, passing the log +// level `logrus.DebugLevel`, the kind "🐞", and the format string and arguments as arguments. The +// `logWithFields` function adds the log level and kind as fields to the log entry and logs the +// formatted message using the logrus logger. func (d *diveLogger) Debugf(format string, args ...interface{}) { d.logWithFields(logrus.DebugLevel, "🐞", format, args...) } +// The `Errorf` function is a method of the `diveLogger` struct. It is used to log an error message +// with the specified error code, format string, and arguments. func (d *diveLogger) Errorf(errorCode ErrorCode, format string, args ...interface{}) { d.logWithFields(logrus.ErrorLevel, "🛑", format, args...) } +// The `Fatalf` function is a method of the `diveLogger` struct. It is used to log an error message +// with the specified error code, format string, and arguments. It calls the `logWithFields` function, +// passing the log level `logrus.FatalLevel`, the kind "💀", and the format string and arguments as +// arguments. The `logWithFields` function adds the log level and kind as fields to the log entry and +// logs the formatted message using the logrus logger. After logging the message, it calls the `Exit` +// function of the logrus logger with a status code of 1, which causes the program to exit. func (d *diveLogger) Fatalf(errorCode ErrorCode, format string, args ...interface{}) { d.logWithFields(logrus.FatalLevel, "💀", format, args...) d.log.Exit(1) diff --git a/cli/common/spinner.go b/cli/common/spinner.go index 687ccf44..f07b923b 100644 --- a/cli/common/spinner.go +++ b/cli/common/spinner.go @@ -8,10 +8,15 @@ import ( "github.com/briandowns/spinner" ) +// The diveSpinner type is a struct that contains a pointer to a spinner.Spinner object. +// spinner - The `spinner` is a pointer to an instance of the `spinner.Spinner` +// +// struct. type diveSpinner struct { spinner *spinner.Spinner } +// The function NewDiveSpinner returns a new instance of the diveSpinner struct. func NewDiveSpinner() *diveSpinner { return &diveSpinner{ @@ -20,40 +25,63 @@ func NewDiveSpinner() *diveSpinner { } +// The `SetSuffixMessage` function is setting the suffix message of the spinner. It takes two +// parameters: `message` and `color`. func (ds *diveSpinner) SetSuffixMessage(message, color string) { ds.spinner.Suffix = message ds.SetColor(color) } + +// The `SetPrefixMessage` function is setting the prefix message of the spinner. It takes a `message` +// parameter and assigns it to the `Prefix` field of the `spinner` object in the `diveSpinner` struct. +// This prefix message will be displayed before the spinner animation. + func (ds *diveSpinner) SetPrefixMessage(message string) { ds.spinner.Prefix = message } +// The `SetColor` function is setting the color of the spinner. It takes a `color` parameter and +// assigns it to the `Color` field of the `spinner` object in the `diveSpinner` struct. This color will +// be used to display the spinner animation. func (ds *diveSpinner) SetColor(color string) { ds.spinner.Color(color) } +// The `Start` function is a method of the `diveSpinner` struct. It takes a `color` parameter and +// starts the spinner animation with the specified color. func (ds *diveSpinner) Start(color string) { ds.SetColor(color) ds.spinner.Start() } +// The `StartWithMessage` function is a method of the `diveSpinner` struct. It takes two parameters: +// `message` and `color`. func (ds *diveSpinner) StartWithMessage(message, color string) { ds.SetSuffixMessage(fmt.Sprint(" ", message), color) ds.Start(color) } +// The `Stop()` function is a method of the `diveSpinner` struct. It checks if the spinner is currently +// active and if so, it stops the spinner animation by calling the `Stop()` method of the `spinner` +// object in the `diveSpinner` struct. func (ds *diveSpinner) Stop() { if ds.spinner.Active() { ds.spinner.Stop() } } +// The `StopWithMessage` function is a method of the `diveSpinner` struct. It takes a `message` +// parameter and performs the following actions: func (ds *diveSpinner) StopWithMessage(message string) { ds.setFinalMessage(message) ds.Stop() } +// The `setFinalMessage` function is a method of the `diveSpinner` struct. It takes a `message` +// parameter and sets the final message of the spinner. This final message will be displayed after the +// spinner animation stops. The function assigns the `message` parameter to the `FinalMSG` field of the +// `spinner` object in the `diveSpinner` struct. func (ds *diveSpinner) setFinalMessage(message string) { ds.spinner.FinalMSG = fmt.Sprint(" ", message) } diff --git a/cli/common/types.go b/cli/common/types.go index cc1ea428..c8354fe2 100644 --- a/cli/common/types.go +++ b/cli/common/types.go @@ -17,6 +17,8 @@ type DiveServiceResponse struct { ChainKey string `json:"chain_key,omitempty"` } +// The `Decode` function is a method of the `DiveServiceResponse` struct. It takes a byte slice +// `responseData` as input and attempts to decode it into a `DiveServiceResponse` object. func (dive *DiveServiceResponse) Decode(responseData []byte) (*DiveServiceResponse, error) { err := json.Unmarshal(responseData, &dive) @@ -25,6 +27,9 @@ func (dive *DiveServiceResponse) Decode(responseData []byte) (*DiveServiceRespon } return dive, nil } + +// The `EncodeToString` function is a method of the `DiveServiceResponse` struct. It encodes the +// `DiveServiceResponse` object into a JSON string representation. func (dive *DiveServiceResponse) EncodeToString() (string, error) { encodedBytes, err := json.Marshal(dive) @@ -37,6 +42,20 @@ func (dive *DiveServiceResponse) EncodeToString() (string, error) { type Services map[string]*DiveServiceResponse +// The EnclaveInfo type represents information about an enclave, including its name, UUID, short UUID, +// creation time, and status. +// @property {string} Name - The name of the enclave. +// @property {string} Uuid - The Uuid property is a unique identifier for the enclave. It is used to +// distinguish one enclave from another. +// @property {string} ShortUuid - The ShortUuid property is a shortened version of the Uuid property. +// It is typically used to provide a more concise representation of the unique identifier for the +// Enclave. +// @property {string} CreatedTime - The CreatedTime property in the EnclaveInfo struct represents the +// timestamp when the enclave was created. It is a string that typically follows a specific date and +// time format, such as "YYYY-MM-DD HH:MM:SS". +// @property {string} Status - The "Status" property in the EnclaveInfo struct represents the current +// status of the enclave. It can have different values depending on the implementation, but some common +// values could be "active", "inactive", "error", or "unavailable". type EnclaveInfo struct { Name string Uuid string @@ -45,6 +64,15 @@ type EnclaveInfo struct { Status string } +// The ConfigLoader interface defines methods for loading default configurations and configurations +// from a file. +// @property {error} LoadDefaultConfig - This method is responsible for loading the default +// configuration. It does not take any arguments and returns an error if there is any issue loading the +// default configuration. +// @property {error} LoadConfigFromFile - This method is responsible for loading a configuration file +// from a given file path. It takes two parameters: a cliContext object, which represents the current +// command-line interface context, and a filePath string, which represents the path to the +// configuration file. The method returns an error if there is any issue loading the type ConfigLoader interface { LoadDefaultConfig() error LoadConfigFromFile(cliContext *Cli, filePath string) error diff --git a/cli/common/utils.go b/cli/common/utils.go index 50ce0350..f88adfd3 100644 --- a/cli/common/utils.go +++ b/cli/common/utils.go @@ -13,6 +13,8 @@ import ( "github.com/kurtosis-tech/stacktrace" ) +// The function "ValidateArgs" checks if the given arguments are empty and returns an error if they are +// not. func ValidateArgs(args []string) error { if len(args) != 0 { @@ -22,6 +24,7 @@ func ValidateArgs(args []string) error { return nil } +// The function writes service response data to a JSON file. func WriteServiceResponseData(serviceName string, data DiveServiceResponse, cliContext *Cli, fileName string) error { var jsonDataFromFile = Services{} err := cliContext.FileHandler().ReadJson(fileName, &jsonDataFromFile) @@ -43,6 +46,7 @@ func WriteServiceResponseData(serviceName string, data DiveServiceResponse, cliC return nil } +// The OpenFile function opens a file using the appropriate command based on the operating system. func OpenFile(URL string) error { var args []string switch runtime.GOOS { @@ -62,6 +66,8 @@ func OpenFile(URL string) error { return nil } +// The function `LoadConfig` loads a configuration either from a default source or from a specified +// file path. func LoadConfig(cliContext *Cli, config ConfigLoader, filePath string) error { if filePath == "" { if err := config.LoadDefaultConfig(); err != nil { @@ -76,6 +82,7 @@ func LoadConfig(cliContext *Cli, config ConfigLoader, filePath string) error { return nil } +// This function returns a StarlarkRunConfig object with the provided parameters. func GetStarlarkRunConfig(params string, relativePathToMainFile string, mainFunctionName string) *starlark_run_config.StarlarkRunConfig { starlarkConfig := &starlark_run_config.StarlarkRunConfig{ @@ -89,6 +96,8 @@ func GetStarlarkRunConfig(params string, relativePathToMainFile string, mainFunc return starlarkConfig } +// The function `GetSerializedData` retrieves serialized data, service information, skipped +// instructions, and any errors from a given response channel. func GetSerializedData(cliContext *Cli, response chan *kurtosis_core_rpc_api_bindings.StarlarkRunResponseLine) (string, map[string]string, map[string]bool, error) { var serializedOutputObj string @@ -153,6 +162,9 @@ func CheckPort(port int) bool { return true } +// The function `GetAvailablePort` generates a random port number between 1024 and 65535 and checks if +// it is available by calling the `CheckPort` function, and returns the first available port or an +// error if no port is available. func GetAvailablePort() (int, error) { // Check random ports in the range 1024-65535