Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Improve the arduino-app-cli version command by adding the "server version" #31#49

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
martacarbone wants to merge2 commits intomain
base:main
Choose a base branch
Loading
fromcli_server_version

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 thearduino-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 inmain.
  • Changes are covered by tests.
  • Logging is meaningful in case of troubleshooting.

lucarin91 reacted with eyes emoji
@CLAassistant
Copy link

CLAassistant commentedNov 6, 2025
edited
Loading

CLA assistant check
All committers have signed the CLA.

Copy link
Contributor

@lucarin91lucarin91 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)
iferr!=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 useurl.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")

returnserverResponse.Version,nil
}

typeserverVersionResponsestruct {
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

}

varserverResponseserverVersionResponse
iferr:=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
iferr:=json.Unmarshal(body,&serverResponse);err!=nil {
varserverResponsestruct {
Versionstring`json:"version"`
}
iferr:=json.NewDecoder(resp.Body).Decode(&serverResponse);err!=nil {


func (rversionResult)String()string {
returnfmt.Sprintf("%s v%s",r.AppName,r.Version)
returnfmt.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.6daemon server at "localhost:8800" v0.6.6

Comment on lines +138 to +139
ClientVersionstring`json:"version"`
ServerVersionstring`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
ClientVersionstring`json:"version"`
ServerVersionstring`json:"serverVersion"`
AppNamestring`json:"app_name"`
Versionstring`json:"version"`
DaemonVersionstring`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 outputhttps://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.

lucarin91 reacted with thumbs up emoji
Comment on lines +55 to +61
funcversionHandler(clientVersionstring,hoststring) {
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"
)
constdefaultDaemon="localhost:8800"

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@lucarin91lucarin91lucarin91 left review comments

@dido18dido18dido18 left review comments

At least 1 approving review is required to merge this pull request.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

4 participants

@martacarbone@CLAassistant@lucarin91@dido18

[8]ページ先頭

©2009-2025 Movatter.jp