Commit 11d9e6e3 authored by Cristian Maglie's avatar Cristian Maglie

Implemented Version grpc command

parent b951097a
......@@ -32,7 +32,7 @@ import (
"github.com/arduino/arduino-cli/commands/config"
"github.com/arduino/arduino-cli/commands/generatedocs"
"github.com/arduino/arduino-cli/commands/sketch"
"github.com/arduino/arduino-cli/commands/version"
"github.com/arduino/arduino-cli/cli/version"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/configs"
paths "github.com/arduino/go-paths-helper"
......@@ -42,7 +42,7 @@ import (
"golang.org/x/crypto/ssh/terminal"
)
// Init prepares the cobra root command.
// Init prepares the cobra root command.
func Init() *cobra.Command {
command := &cobra.Command{
Use: "arduino-cli",
......
......@@ -18,10 +18,9 @@
package version
import (
"fmt"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/common/formatter/output"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
......@@ -38,11 +37,17 @@ func InitCommand() *cobra.Command {
return versionCommand
}
type versionOutput struct {
Command string `json:"command"`
Version string `json:"version"`
}
func run(cmd *cobra.Command, args []string) {
logrus.Info("Calling version command on `arduino`")
versionInfo := output.VersionResult{
CommandName: cmd.Parent().Name(),
Version: cli.Version,
res := &versionOutput{
Command: cmd.Parent().Name(),
Version: cli.Version,
}
if cli.OutputJSONOrElse(res) {
fmt.Printf("%s version %s\n", res.Command, res.Version)
}
formatter.Print(versionInfo)
}
/*
* This file is part of arduino-cli.
*
* Copyright 2018 ARDUINO SA (http://www.arduino.cc/)
*
* This software is released under the GNU General Public License version 3,
* which covers the main part of arduino-cli.
* The terms of this license can be found at:
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
* You can be released from the requirements of the above licenses by purchasing
* a commercial license. Buying such a license is mandatory if you want to modify or
* otherwise use the software for commercial activities involving the Arduino
* software without disclosing the source code of your own applications. To purchase
* a commercial license, send an email to license@arduino.cc.
*/
package output
import "fmt"
// VersionResult represents the output of the version commands.
type VersionResult struct {
CommandName string `json:"command,required"`
Version string `json:"version,required"`
}
func (vr VersionResult) String() string {
return fmt.Sprintf("%s version %s", vr.CommandName, vr.Version)
}
......@@ -44,6 +44,15 @@ func main() {
client := rpc.NewArduinoCoreClient(conn)
fmt.Println()
// VERSION
fmt.Println("=== calling Version")
versionResp, err := client.Version(context.Background(), &rpc.VersionReq{})
if err != nil {
fmt.Printf("Error getting version: %s\n", err)
os.Exit(1)
}
fmt.Printf("---> %+v\n\v", versionResp)
// INIT
fmt.Println("=== calling Init")
initRespStream, err := client.Init(context.Background(), &rpc.InitReq{
......
......@@ -26,6 +26,7 @@ import (
"log"
"net"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/commands/compile"
......@@ -119,6 +120,10 @@ func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_In
return stream.Send(resp)
}
func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq) (*rpc.VersionResp, error) {
return &rpc.VersionResp{Version: cli.Version}, nil
}
func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error {
resp, err := compile.Compile(
stream.Context(), req,
......
This diff is collapsed.
......@@ -48,6 +48,8 @@ service ArduinoCore {
// Update libraries index
rpc UpdateLibrariesIndex(UpdateLibrariesIndexReq) returns (stream UpdateLibrariesIndexResp) {}
rpc Version(VersionReq) returns (VersionResp) {}
// BOARD COMMANDS
// --------------
......@@ -148,3 +150,9 @@ message UpdateLibrariesIndexReq {
message UpdateLibrariesIndexResp {
DownloadProgress download_progress = 1;
}
message VersionReq {}
message VersionResp {
string version = 1;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment