Hello Team, I need one clarification on this <Defa...
# atmos-dev
p
Hello Team, I need one clarification on this Default value for demo argument should not cause an error Where there is multiple arguments are required, if user doesn't provide one, in that case, it is hard to identify the order of argument given by user. What should we do in this case? My opinion: For flags, we have that option to keep flag optional with default value. It seems, arguments are always required and users have to pass those. But if user doesn't give any arguments, only then we can use the default arguments for any command. But If they pass some and skip some, there is no way to identify which arguments are missing and which are given. Please share your thoughts! Thank you so much!
a
Cobra does all of that and shows the error message and usage if any argument is missing, or a required flag is not provided
looks like you are talking abou Atmos custom commands
in custom commands, we have the
required
feild for flags
Copy code
type CommandFlag struct {
	Name        string `yaml:"name" json:"name" mapstructure:"name"`
	Shorthand   string `yaml:"shorthand" json:"shorthand" mapstructure:"shorthand"`
	Type        string `yaml:"type" json:"type" mapstructure:"type"`
	Description string `yaml:"description" json:"description" mapstructure:"description"`
	Usage       string `yaml:"usage" json:"usage" mapstructure:"usage"`
	Required    bool   `yaml:"required" json:"required" mapstructure:"required"`
}
we can add the same for the arguments here
Copy code
type CommandArgument struct {
	Name        string `yaml:"name" json:"name" mapstructure:"name"`
	Description string `yaml:"description" json:"description" mapstructure:"description"`
}
and add
default
field to both arguments and flags
Copy code
type CommandFlag struct {
	Name        string `yaml:"name" json:"name" mapstructure:"name"`
	Shorthand   string `yaml:"shorthand" json:"shorthand" mapstructure:"shorthand"`
	Type        string `yaml:"type" json:"type" mapstructure:"type"`
	Description string `yaml:"description" json:"description" mapstructure:"description"`
	Usage       string `yaml:"usage" json:"usage" mapstructure:"usage"`
	Required    bool   `yaml:"required" json:"required" mapstructure:"required"`
    Default     any   `yaml:"default" json:"default" mapstructure:"default"`
}
Copy code
type CommandArgument struct {
	Name        string `yaml:"name" json:"name" mapstructure:"name"`
	Description string `yaml:"description" json:"description" mapstructure:"description"`
	Required    bool   `yaml:"required" json:"required" mapstructure:"required"`
    Default     any   `yaml:"default" json:"default" mapstructure:"default"`
}
this way, the user would control what is required and provide the default values
the
default
and
required
need to be sent to Cobra (as we do for the other fields of the commands), and Cobra will take care of missing arguments and flags and show the message and the usage
p
thank you for the info. Let me try this approach
👍 1
Hi @Andriy Knysh (Cloud Posse) I have tried to implement in this way. But while working on this, one more question come to my mind: let's assume for one custom command, we have two args and user provide only one arg. In this case how we can figure out the arg order i.e. how to determind the user arg is the first arg or the second one?
a
thank you @Pulak Kanti Bhowmick let me review the PR