Skip to content

Conversation

@martacarbone
Copy link

Motivation

When running arduino-app-cli version instead of only returning the version of the currently run executable (the CLI) we should also return the version of the "server" (the daemon/service running and waiting for HTTP API requests).

Change description

This change make a version request to the running daemon and adds the output to the arduino-app-cli version command.
It also adds "ServerVersion" and removes "AppName" from the output.

Additional Notes

Reviewer checklist

  • PR addresses a single concern.
  • PR title and description are properly filled.
  • Changes will be merged in main.
  • Changes are covered by tests.
  • Logging is meaningful in case of troubleshooting.

@CLAassistant
Copy link

CLAassistant commented Nov 6, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@lucarin91 lucarin91 left a comment

Choose a reason for hiding this comment

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

Looks good, I added some minor suggestions to make it more readable (in my opinion)

Comment on lines +64 to +67
url, err := getValidOrDefaultUrl(host)
if err != nil {
feedback.Fatal(i18n.Tr("Error: invalid host:port format"), feedback.ErrBadArgument)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you can just use url.Parse, but anyway I would parse the url right after getting the flag, e.g., host, _ := cmd.Flags().GetString("host"), so you can directly handle the error.
Then here you can just add the path with

url = url.Join("/v1/version")

return serverResponse.Version, nil
}

type serverVersionResponse struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Usually structs used only for parsing JSON are defined directly inside the function that uses them

}

var serverResponse serverVersionResponse
if err := json.Unmarshal(body, &serverResponse); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably in this case, you aren't improving much, but usually it is better to make JSON handling the decoding buffer instead of reading the body into a buffer and then passing it to json library.

Suggested change
if err := json.Unmarshal(body, &serverResponse); err != nil {
var serverResponse struct {
Version string `json:"version"`
}
if err := json.NewDecoder(resp.Body).Decode(&serverResponse); err != nil {


func (r versionResult) String() string {
return fmt.Sprintf("%s v%s", r.AppName, r.Version)
return fmt.Sprintf("client: %s\nserver: %s",
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering if we should make a more text-friendly line like

Arduino App CLI v0.6.6
daemon server at "localhost:8800" v0.6.6

Comment on lines +138 to +139
ClientVersion string `json:"version"`
ServerVersion string `json:"serverVersion"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I would probably return those info

Suggested change
ClientVersion string `json:"version"`
ServerVersion string `json:"serverVersion"`
AppName string `json:"app_name"`
Version string `json:"version"`
DaemonVersion string `json:"daemon_version"`

Copy link
Contributor

Choose a reason for hiding this comment

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

We could print the name with the arduino-flasher-cli output https://github.com/arduino/arduino-flasher-cli/blob/1899741a4e890a2ff0727669d23d25b6499e0522/main.go#L63

Arduino App CLI 

BUT I would avoid theapp_name that can be misleading (the term "app" is for the Arduino Apps).

maybe only "name" in the json field.

Comment on lines +55 to +61
func versionHandler(clientVersion string, host string) {
httpClient := http.Client{
Timeout: time.Second,
}
result := doVersionHandler(httpClient, clientVersion, host)
feedback.PrintResult(result)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this extra function is too much. I think it is ok to just move this code directly inside the Run function of the cobra command.

Comment on lines +35 to +38
const (
DefaultHostname = "localhost"
DefaultPort = "8800"
)
Copy link
Contributor

Choose a reason for hiding this comment

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

if there isn't any reason, I would just define a single const

Suggested change
const (
DefaultHostname = "localhost"
DefaultPort = "8800"
)
const defaultDaemon = "localhost:8800"

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.

4 participants