Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow printing a command-line equivalent of a command #173

Merged
merged 1 commit into from
Mar 7, 2023

Conversation

Annopaolo
Copy link
Collaborator

@Annopaolo Annopaolo commented Feb 15, 2023

Add the --to-curl flag to allow the user to get a bash command equivalent to the one astartectl would run.
If the flag is set, astartectl will take no futher action.
Closes #100.

@Annopaolo
Copy link
Collaborator Author

Based, based on #172.

@Annopaolo Annopaolo force-pushed the to-curl branch 2 times, most recently from 8d41290 to 9cd09e2 Compare February 27, 2023 10:32
@Annopaolo Annopaolo marked this pull request as ready for review March 7, 2023 11:08
utils/cmdline.go Outdated
Comment on lines 77 to 82
func MaybeCurlAndExit(req client.AstarteRequest, client *client.Client) {
if viper.GetBool("appengine-to-curl") || viper.GetBool("housekeeping-to-curl") || viper.GetBool("pairing-to-curl") || viper.GetBool("realmmanagement-to-curl") {
fmt.Println(req.ToCurl(client))
os.Exit(0)
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of duplicating the implementation, why not

Suggested change
func MaybeCurlAndExit(req client.AstarteRequest, client *client.Client) {
if viper.GetBool("appengine-to-curl") || viper.GetBool("housekeeping-to-curl") || viper.GetBool("pairing-to-curl") || viper.GetBool("realmmanagement-to-curl") {
fmt.Println(req.ToCurl(client))
os.Exit(0)
}
}
func MaybeCurlAndExit(req client.AstarteRequest, client *client.Client) {
MaybeCurl(req, client)
os.Exit(0)
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's no good because MaybeCurlAndExit would exit even if all *-to-curl are false. Using something like

func ShouldCurl() bool {
  return viper.GetBool("appengine-to-curl") || viper.GetBool("housekeeping-to-curl") || viper.GetBool("pairing-to-curl") || viper.GetBool("realmmanagement-to-curl")
}

instead of that condition might be a better solution, though.

@@ -571,6 +581,9 @@ func devicesDataSnapshotF(command *cobra.Command, args []string) error {
if err != nil {
warnOrFail(snapshotInterface, i.Name, err)
}

utils.MaybeCurl(snapshotCall, astarteAPIClient)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to print the equivalent curl and run the request.
We should consider a more robust approach

@@ -333,6 +349,9 @@ func getInterfaceDefinition(realm, interfaceName string, interfaceMajor int) (in
return interfaces.AstarteInterface{}, err
}

// don't care about `interface sync` because its flag is always false
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment relevant? (check also the ones below)

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is relevant, but a bit too obscure. Will reword.

Add the `--to-curl` flag to print get a bash command
equivalent to the one astartectl would run.
If the flag is set, astartectl will take no futher action.

Signed-off-by: Arnaldo Cesco <arnaldo.cesco@secomind.com>
@matt-mazzucato matt-mazzucato merged commit 1d59a86 into astarte-platform:release-22.11 Mar 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants