Unverified Commit 3d797f54 authored by Luca Cipriani's avatar Luca Cipriani Committed by GitHub

Merge pull request #272 from arduino/massi/monitor

Rearrange cli commands
parents aa21da5a 08b6e95b
......@@ -21,7 +21,9 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -33,9 +35,9 @@ func initAttachCommand() *cobra.Command {
Use: "attach <port>|<FQBN> [sketchPath]",
Short: "Attaches a sketch to a board.",
Long: "Attaches a sketch to a board.",
Example: " " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0\n" +
" " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0 HelloWorld\n" +
" " + cli.VersionInfo.Application + " board attach arduino:samd:mkr1000",
Example: " " + os.Args[0] + " board attach serial:///dev/tty/ACM0\n" +
" " + os.Args[0] + " board attach serial:///dev/tty/ACM0 HelloWorld\n" +
" " + os.Args[0] + " board attach arduino:samd:mkr1000",
Args: cobra.RangeArgs(1, 2),
Run: runAttachCommand,
}
......@@ -49,7 +51,7 @@ var attachFlags struct {
}
func runAttachCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
var path string
if len(args) > 0 {
path = args[1]
......@@ -59,9 +61,9 @@ func runAttachCommand(cmd *cobra.Command, args []string) {
BoardUri: args[0],
SketchPath: path,
SearchTimeout: attachFlags.searchTimeout,
}, cli.OutputTaskProgress())
}, output.TaskProgress())
if err != nil {
formatter.PrintError(err, "attach board error")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
......@@ -18,24 +18,27 @@
package board
import (
"github.com/arduino/arduino-cli/cli"
"os"
"github.com/spf13/cobra"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
// NewCommand created a new `board` command
func NewCommand() *cobra.Command {
boardCommand := &cobra.Command{
Use: "board",
Short: "Arduino board commands.",
Long: "Arduino board commands.",
Example: " # Lists all connected boards.\n" +
" " + cli.VersionInfo.Application + " board list\n\n" +
" " + os.Args[0] + " board list\n\n" +
" # Attaches a sketch to a board.\n" +
" " + cli.VersionInfo.Application + " board attach serial:///dev/tty/ACM0 mySketch",
" " + os.Args[0] + " board attach serial:///dev/tty/ACM0 mySketch",
}
boardCommand.AddCommand(initAttachCommand())
boardCommand.AddCommand(initDetailsCommand())
boardCommand.AddCommand(detailsCommand)
boardCommand.AddCommand(initListCommand())
boardCommand.AddCommand(initListAllCommand())
boardCommand.AddCommand(listAllCommand)
return boardCommand
}
......@@ -22,39 +22,35 @@ import (
"fmt"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/output"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/spf13/cobra"
)
func initDetailsCommand() *cobra.Command {
detailsCommand := &cobra.Command{
Use: "details <FQBN>",
Short: "Print details about a board.",
Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.",
Example: " " + cli.VersionInfo.Application + " board details arduino:avr:nano",
Args: cobra.ExactArgs(1),
Run: runDetailsCommand,
}
return detailsCommand
var detailsCommand = &cobra.Command{
Use: "details <FQBN>",
Short: "Print details about a board.",
Long: "Show information about a board, in particular if the board has options to be specified in the FQBN.",
Example: " " + os.Args[0] + " board details arduino:avr:nano",
Args: cobra.ExactArgs(1),
Run: runDetailsCommand,
}
func runDetailsCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
res, err := board.Details(context.Background(), &rpc.BoardDetailsReq{
Instance: instance,
Instance: instance.CreateInstance(),
Fqbn: args[0],
})
if err != nil {
formatter.PrintError(err, "Error getting board details")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
if cli.OutputJSONOrElse(res) {
if output.JSONOrElse(res) {
outputDetailsResp(res)
}
}
......
......@@ -24,10 +24,11 @@ import (
"sort"
"time"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/output"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/spf13/cobra"
)
......@@ -37,7 +38,7 @@ func initListCommand() *cobra.Command {
Use: "list",
Short: "List connected boards.",
Long: "Detects and displays a list of connected boards to the current computer.",
Example: " " + cli.VersionInfo.Application + " board list --timeout 10s",
Example: " " + os.Args[0] + " board list --timeout 10s",
Args: cobra.NoArgs,
Run: runListCommand,
}
......@@ -53,22 +54,20 @@ var listFlags struct {
// runListCommand detects and lists the connected arduino boards
func runListCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
if timeout, err := time.ParseDuration(listFlags.timeout); err != nil {
formatter.PrintError(err, "Invalid timeout.")
os.Exit(cli.ErrBadArgument)
os.Exit(errorcodes.ErrBadArgument)
} else {
time.Sleep(timeout)
}
resp, err := board.List(context.Background(), &rpc.BoardListReq{Instance: instance})
resp, err := board.List(context.Background(), &rpc.BoardListReq{Instance: instance.CreateInstance()})
if err != nil {
formatter.PrintError(err, "Error detecting boards")
os.Exit(cli.ErrNetwork)
os.Exit(errorcodes.ErrNetwork)
}
if cli.OutputJSONOrElse(resp) {
if output.JSONOrElse(resp) {
outputListResp(resp)
}
}
......
......@@ -23,33 +23,31 @@ import (
"os"
"sort"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/board"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/output"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/spf13/cobra"
)
func initListAllCommand() *cobra.Command {
listAllCommand := &cobra.Command{
Use: "listall [boardname]",
Short: "List all known boards and their corresponding FQBN.",
Long: "" +
"List all boards that have the support platform installed. You can search\n" +
"for a specific board if you specify the board name",
Example: "" +
" " + cli.VersionInfo.Application + " board listall\n" +
" " + cli.VersionInfo.Application + " board listall zero",
Args: cobra.ArbitraryArgs,
Run: runListAllCommand,
}
return listAllCommand
var listAllCommand = &cobra.Command{
Use: "listall [boardname]",
Short: "List all known boards and their corresponding FQBN.",
Long: "" +
"List all boards that have the support platform installed. You can search\n" +
"for a specific board if you specify the board name",
Example: "" +
" " + os.Args[0] + " board listall\n" +
" " + os.Args[0] + " board listall zero",
Args: cobra.ArbitraryArgs,
Run: runListAllCommand,
}
// runListAllCommand list all installed boards
func runListAllCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
list, err := board.ListAll(context.Background(), &rpc.BoardListAllReq{
Instance: instance,
......@@ -57,9 +55,10 @@ func runListAllCommand(cmd *cobra.Command, args []string) {
})
if err != nil {
formatter.PrintError(err, "Error listing boards")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
if cli.OutputJSONOrElse(list) {
if output.JSONOrElse(list) {
outputBoardListAll(list)
}
}
......
/*
* This file is part of arduino-cli.
* This file is part of arduino-
*
* 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.
* which covers the main part of arduino-
* The terms of this license can be found at:
* https://www.gnu.org/licenses/gpl-3.0.en.html
*
......@@ -18,152 +18,106 @@
package cli
import (
"context"
"errors"
"fmt"
"net/http"
"io/ioutil"
"os"
"path/filepath"
"runtime"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/libraries/librariesmanager"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/cli/board"
"github.com/arduino/arduino-cli/cli/compile"
"github.com/arduino/arduino-cli/cli/config"
"github.com/arduino/arduino-cli/cli/core"
"github.com/arduino/arduino-cli/cli/daemon"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/generatedocs"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/lib"
"github.com/arduino/arduino-cli/cli/sketch"
"github.com/arduino/arduino-cli/cli/upload"
"github.com/arduino/arduino-cli/cli/version"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/configs"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/arduino-cli/version"
"github.com/arduino/go-paths-helper"
"github.com/mattn/go-colorable"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)
// Error codes to be used for os.Exit().
const (
_ = iota // 0 is not a valid exit error code
ErrGeneric // 1 is the reserved "catchall" code in Unix
_ // 2 is reserved in Unix
ErrNoConfigFile
ErrBadCall
ErrNetwork
// ErrCoreConfig represents an error in the cli core config, for example some basic
// files shipped with the installation are missing, or cannot create or get basic
// directories vital for the CLI to work.
ErrCoreConfig
ErrBadArgument
)
// appName is the command line name of the Arduino CLI executable on the user system (users may change it)
var appName = filepath.Base(os.Args[0])
// VersionInfo contains all info injected during build
var VersionInfo = version.NewInfo(appName)
// HTTPClientHeader is the object that will be propagated to configure the clients inside the downloaders
var HTTPClientHeader = getHTTPClientHeader()
// ErrLogrus represents the logrus instance, which has the role to
// log all non info messages.
var ErrLogrus = logrus.New()
// GlobalFlags represents flags available in all the program.
var GlobalFlags struct {
Debug bool // If true, dump debug output to stderr.
OutputJSON bool // true output in JSON, false output as Text
}
// Config FIXMEDOC
var Config *configs.Configuration
func packageManagerInitReq() *rpc.InitReq {
urls := []string{}
for _, URL := range Config.BoardManagerAdditionalUrls {
urls = append(urls, URL.String())
var (
// ArduinoCli is the root command
ArduinoCli = &cobra.Command{
Use: "arduino-cli",
Short: "Arduino CLI.",
Long: "Arduino Command Line Interface (arduino-cli).",
Example: " " + os.Args[0] + " <command> [flags...]",
PersistentPreRun: preRun,
}
conf := &rpc.Configuration{}
conf.DataDir = Config.DataDir.String()
conf.DownloadsDir = Config.DownloadsDir().String()
conf.BoardManagerAdditionalUrls = urls
if Config.SketchbookDir != nil {
conf.SketchbookDir = Config.SketchbookDir.String()
}
// ErrLogrus represents the logrus instance, which has the role to
// log all non info messages.
ErrLogrus = logrus.New()
return &rpc.InitReq{Configuration: conf}
}
outputFormat string
)
func getHTTPClientHeader() http.Header {
userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", VersionInfo.Application,
VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), VersionInfo.Commit, VersionInfo.BuildDate)
downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}}
return downloaderHeaders
// Init the cobra root command
func init() {
createCliCommandTree(ArduinoCli)
}
// InitInstance FIXMEDOC
func InitInstance() *rpc.InitResp {
logrus.Info("Initializing package manager")
req := packageManagerInitReq()
resp, err := commands.Init(context.Background(), req, OutputProgressBar(), OutputTaskProgress(), HTTPClientHeader)
if err != nil {
formatter.PrintError(err, "Error initializing package manager")
os.Exit(ErrGeneric)
}
if resp.GetLibrariesIndexError() != "" {
commands.UpdateLibrariesIndex(context.Background(),
&rpc.UpdateLibrariesIndexReq{Instance: resp.GetInstance()}, OutputProgressBar())
rescResp, err := commands.Rescan(context.Background(), &rpc.RescanReq{Instance: resp.GetInstance()})
if rescResp.GetLibrariesIndexError() != "" {
formatter.PrintErrorMessage("Error loading library index: " + rescResp.GetLibrariesIndexError())
os.Exit(ErrGeneric)
}
if err != nil {
formatter.PrintError(err, "Error loading library index")
os.Exit(ErrGeneric)
}
resp.LibrariesIndexError = rescResp.LibrariesIndexError
resp.PlatformsIndexErrors = rescResp.PlatformsIndexErrors
}
return resp
// this is here only for testing
func createCliCommandTree(cmd *cobra.Command) {
cmd.AddCommand(board.NewCommand())
cmd.AddCommand(compile.NewCommand())
cmd.AddCommand(config.NewCommand())
cmd.AddCommand(core.NewCommand())
cmd.AddCommand(daemon.NewCommand())
cmd.AddCommand(generatedocs.NewCommand())
cmd.AddCommand(lib.NewCommand())
cmd.AddCommand(sketch.NewCommand())
cmd.AddCommand(upload.NewCommand())
cmd.AddCommand(version.NewCommand())
cmd.PersistentFlags().BoolVar(&globals.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).")
cmd.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be [text|json].")
cmd.PersistentFlags().StringVar(&globals.YAMLConfigFile, "config-file", "", "The custom config file (if not specified the default will be used).")
}
// CreateInstance creates and return an instance of the Arduino Core engine
func CreateInstance() *rpc.Instance {
resp := InitInstance()
if resp.GetPlatformsIndexErrors() != nil {
for _, err := range resp.GetPlatformsIndexErrors() {
formatter.PrintError(errors.New(err), "Error loading index")
func preRun(cmd *cobra.Command, args []string) {
// Reset logrus if debug flag changed.
if !globals.Debug {
// Discard logrus output if no debug.
logrus.SetOutput(ioutil.Discard)
} else {
// Else print on stderr.
// Workaround to get colored output on windows
if terminal.IsTerminal(int(os.Stdout.Fd())) {
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
}
formatter.PrintErrorMessage("Launch '" + VersionInfo.Application + " core update-index' to fix or download indexes.")
os.Exit(ErrGeneric)
logrus.SetOutput(colorable.NewColorableStdout())
ErrLogrus.Out = colorable.NewColorableStderr()
formatter.SetLogger(ErrLogrus)
}
return resp.GetInstance()
}
// CreateInstaceIgnorePlatformIndexErrors creates and return an instance of the
// Arduino Core Engine, but won't stop on platforms index loading errors.
func CreateInstaceIgnorePlatformIndexErrors() *rpc.Instance {
return InitInstance().GetInstance()
}
// InitPackageAndLibraryManager initializes the PackageManager and the
// LibaryManager with the default configuration. (DEPRECATED)
func InitPackageAndLibraryManager() (*packagemanager.PackageManager, *librariesmanager.LibrariesManager) {
resp := InitInstance()
return commands.GetPackageManager(resp), commands.GetLibraryManager(resp)
}
// InitSketchPath returns sketchPath if specified or the current working
// directory if sketchPath is nil.
func InitSketchPath(sketchPath *paths.Path) *paths.Path {
if sketchPath != nil {
return sketchPath
globals.InitConfigs()
logrus.Info(globals.VersionInfo.Application + "-" + globals.VersionInfo.VersionString)
logrus.Info("Starting root command preparation (`arduino`)")
switch outputFormat {
case "text":
formatter.SetFormatter("text")
globals.OutputJSON = false
case "json":
formatter.SetFormatter("json")
globals.OutputJSON = true
default:
formatter.PrintErrorMessage("Invalid output format: " + outputFormat)
os.Exit(errorcodes.ErrBadCall)
}
wd, err := paths.Getwd()
if err != nil {
formatter.PrintError(err, "Couldn't get current working directory")
os.Exit(ErrGeneric)
logrus.Info("Formatter set")
if !formatter.IsCurrentFormat("text") {
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
logrus.Warn("Calling help on JSON format")
formatter.PrintErrorMessage("Invalid Call : should show Help, but it is available only in TEXT mode.")
os.Exit(errorcodes.ErrBadCall)
})
}
logrus.Infof("Reading sketch from dir: %s", wd)
return wd
}
This diff is collapsed.
......@@ -21,61 +21,19 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/compile"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
command := &cobra.Command{
Use: "compile",
Short: "Compiles Arduino sketches.",
Long: "Compiles Arduino sketches.",
Example: " " + cli.VersionInfo.Application + " compile -b arduino:avr:uno /home/user/Arduino/MySketch",
Args: cobra.MaximumNArgs(1),
Run: run,
}
command.Flags().StringVarP(
&flags.fqbn, "fqbn", "b", "",
"Fully Qualified Board Name, e.g.: arduino:avr:uno")
command.Flags().BoolVar(
&flags.showProperties, "show-properties", false,
"Show all build properties used instead of compiling.")
command.Flags().BoolVar(
&flags.preprocess, "preprocess", false,
"Print preprocessed code to stdout instead of compiling.")
command.Flags().StringVar(
&flags.buildCachePath, "build-cache-path", "",
"Builds of 'core.a' are saved into this path to be cached and reused.")
command.Flags().StringVarP(
&flags.exportFile, "output", "o", "",
"Filename of the compile output.")
command.Flags().StringVar(
&flags.buildPath, "build-path", "",
"Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS.")
command.Flags().StringSliceVar(
&flags.buildProperties, "build-properties", []string{},
"List of custom build properties separated by commas. Or can be used multiple times for multiple properties.")
command.Flags().StringVar(
&flags.warnings, "warnings", "none",
`Optional, can be "none", "default", "more" and "all". Defaults to "none". Used to tell gcc which warning level to use (-W flag).`)
command.Flags().BoolVarP(
&flags.verbose, "verbose", "v", false,
"Optional, turns on verbose mode.")
command.Flags().BoolVar(
&flags.quiet, "quiet", false,
"Optional, supresses almost every output.")
command.Flags().StringVar(
&flags.vidPid, "vid-pid", "",
"When specified, VID/PID specific build properties are used, if boards supports them.")
return command
}
var flags struct {
var (
fqbn string // Fully Qualified Board Name, e.g.: arduino:avr:uno.
showProperties bool // Show all build preferences used instead of compiling.
preprocess bool // Print preprocessed code to stdout.
......@@ -87,39 +45,80 @@ var flags struct {
quiet bool // Suppresses almost every output.
vidPid string // VID/PID specific build properties.
exportFile string // The compiled binary is written to this file
)
// NewCommand created a new `compile` command
func NewCommand() *cobra.Command {
command := &cobra.Command{
Use: "compile",
Short: "Compiles Arduino sketches.",
Long: "Compiles Arduino sketches.",
Example: " " + os.Args[0] + " compile -b arduino:avr:uno /home/user/Arduino/MySketch",
Args: cobra.MaximumNArgs(1),
Run: run,
}
command.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno")
command.Flags().BoolVar(&showProperties, "show-properties", false, "Show all build properties used instead of compiling.")
command.Flags().BoolVar(&preprocess, "preprocess", false, "Print preprocessed code to stdout instead of compiling.")
command.Flags().StringVar(&buildCachePath, "build-cache-path", "", "Builds of 'core.a' are saved into this path to be cached and reused.")
command.Flags().StringVarP(&exportFile, "output", "o", "", "Filename of the compile output.")
command.Flags().StringVar(&buildPath, "build-path", "",
"Path where to save compiled files. If omitted, a directory will be created in the default temporary path of your OS.")
command.Flags().StringSliceVar(&buildProperties, "build-properties", []string{},
"List of custom build properties separated by commas. Or can be used multiple times for multiple properties.")
command.Flags().StringVar(&warnings, "warnings", "none",
`Optional, can be "none", "default", "more" and "all". Defaults to "none". Used to tell gcc which warning level to use (-W flag).`)
command.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
command.Flags().BoolVar(&quiet, "quiet", false, "Optional, supresses almost every output.")
command.Flags().StringVar(&vidPid, "vid-pid", "", "When specified, VID/PID specific build properties are used, if boards supports them.")
return command
}
func run(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
var path *paths.Path
if len(args) > 0 {
path = paths.New(args[0])
}
sketchPath := cli.InitSketchPath(path)
compRes, err := compile.Compile(context.Background(), &rpc.CompileReq{
sketchPath := initSketchPath(path)
_, err := compile.Compile(context.Background(), &rpc.CompileReq{
Instance: instance,
Fqbn: flags.fqbn,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
ShowProperties: flags.showProperties,
Preprocess: flags.preprocess,
BuildCachePath: flags.buildCachePath,
BuildPath: flags.buildPath,
BuildProperties: flags.buildProperties,
Warnings: flags.warnings,
Verbose: flags.verbose,
Quiet: flags.quiet,
VidPid: flags.vidPid,
ExportFile: flags.exportFile,
}, os.Stdout, os.Stderr)
if err == nil {
outputCompileResp(compRes)
} else {
ShowProperties: showProperties,
Preprocess: preprocess,
BuildCachePath: buildCachePath,
BuildPath: buildPath,
BuildProperties: buildProperties,
Warnings: warnings,
Verbose: verbose,
Quiet: quiet,
VidPid: vidPid,
ExportFile: exportFile,
}, os.Stdout, os.Stderr, globals.Config, globals.Debug)
if err != nil {
formatter.PrintError(err, "Error during build")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
func outputCompileResp(details *rpc.CompileResp) {
// initSketchPath returns the current working directory
func initSketchPath(sketchPath *paths.Path) *paths.Path {
if sketchPath != nil {
return sketchPath
}
wd, err := paths.Getwd()
if err != nil {
formatter.PrintError(err, "Couldn't get current working directory")
os.Exit(errorcodes.ErrGeneric)
}
logrus.Infof("Reading sketch from dir: %s", wd)
return wd
}
......@@ -18,18 +18,21 @@
package config
import (
"github.com/arduino/arduino-cli/cli"
"os"
"github.com/spf13/cobra"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
// NewCommand created a new `config` command
func NewCommand() *cobra.Command {
configCommand := &cobra.Command{
Use: "config",
Short: "Arduino Configuration Commands.",
Example: " " + cli.VersionInfo.Application + " config init",
Example: " " + os.Args[0] + " config init",
}
configCommand.AddCommand(initDumpCommand())
configCommand.AddCommand(dumpCmd)
configCommand.AddCommand(initInitCommand())
return configCommand
}
......@@ -21,30 +21,29 @@ import (
"fmt"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func initDumpCommand() *cobra.Command {
return &cobra.Command{
Use: "dump",
Short: "Prints the current configuration",
Long: "Prints the current configuration.",
Example: " " + cli.VersionInfo.Application + " config dump",
Args: cobra.NoArgs,
Run: runDumpCommand,
}
var dumpCmd = &cobra.Command{
Use: "dump",
Short: "Prints the current configuration",
Long: "Prints the current configuration.",
Example: " " + os.Args[0] + " config dump",
Args: cobra.NoArgs,
Run: runDumpCommand,
}
func runDumpCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino config dump`")
data, err := cli.Config.SerializeToYAML()
data, err := globals.Config.SerializeToYAML()
if err != nil {
formatter.PrintError(err, "Error creating configuration")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
fmt.Println(string(data))
......
......@@ -20,7 +20,8 @@ package config
import (
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
......@@ -33,9 +34,9 @@ func initInitCommand() *cobra.Command {
Long: "Initializes a new config file into the default location ($EXE_DIR/cli-config.yml).",
Example: "" +
" # Creates a config file by asking questions to the user into the default location.\n" +
" " + cli.VersionInfo.Application + " config init\n\n" +
" " + os.Args[0] + " config init\n\n" +
" # Creates a config file with default configuration into default location.\n" +
" " + cli.VersionInfo.Application + " config init --default\n",
" " + os.Args[0] + " config init --default\n",
Args: cobra.NoArgs,
Run: runInitCommand,
}
......@@ -57,23 +58,23 @@ func runInitCommand(cmd *cobra.Command, args []string) {
if !initFlags._default {
if !formatter.IsCurrentFormat("text") {
formatter.PrintErrorMessage("The interactive mode is supported only in text mode.")
os.Exit(cli.ErrBadCall)
os.Exit(errorcodes.ErrBadCall)
}
}
filepath := initFlags.location
if filepath == "" {
filepath = cli.Config.ConfigFile.String()
filepath = globals.Config.ConfigFile.String()
}
if err := cli.Config.ConfigFile.Parent().MkdirAll(); err != nil {
if err := globals.Config.ConfigFile.Parent().MkdirAll(); err != nil {
formatter.PrintError(err, "Cannot create config file.")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
if err := cli.Config.SaveToYAML(filepath); err != nil {
if err := globals.Config.SaveToYAML(filepath); err != nil {
formatter.PrintError(err, "Cannot create config file.")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
formatter.PrintResult("Config file PATH: " + filepath)
logrus.Info("Done")
......
......@@ -22,7 +22,7 @@ import (
"os"
"strings"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/common/formatter"
)
......@@ -47,7 +47,7 @@ func parsePlatformReferenceArgs(args []string) []*platformReferenceArg {
reference, err := parsePlatformReferenceArg(arg)
if err != nil {
formatter.PrintError(err, "Invalid item "+arg)
os.Exit(cli.ErrBadArgument)
os.Exit(errorcodes.ErrBadArgument)
}
ret = append(ret, reference)
}
......
......@@ -18,18 +18,20 @@
package core
import (
"github.com/arduino/arduino-cli/cli"
"os"
"github.com/spf13/cobra"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
// NewCommand created a new `core` command
func NewCommand() *cobra.Command {
coreCommand := &cobra.Command{
Use: "core",
Short: "Arduino Core operations.",
Long: "Arduino Core operations.",
Example: " " + cli.VersionInfo.Application + " core update-index",
Example: " " + os.Args[0] + " core update-index",
}
coreCommand.AddCommand(initDownloadCommand())
coreCommand.AddCommand(initInstallCommand())
coreCommand.AddCommand(initListCommand())
......@@ -37,5 +39,6 @@ func InitCommand() *cobra.Command {
coreCommand.AddCommand(initUpgradeCommand())
coreCommand.AddCommand(initUninstallCommand())
coreCommand.AddCommand(initSearchCommand())
return coreCommand
}
......@@ -21,7 +21,10 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -35,8 +38,8 @@ func initDownloadCommand() *cobra.Command {
Short: "Downloads one or more cores and corresponding tool dependencies.",
Long: "Downloads one or more cores and corresponding tool dependencies.",
Example: "" +
" " + cli.VersionInfo.Application + " core download arduino:samd # to download the latest version of arduino SAMD core.\n" +
" " + cli.VersionInfo.Application + " core download arduino:samd=1.6.9 # for a specific version (in this case 1.6.9).",
" " + os.Args[0] + " core download arduino:samd # to download the latest version of arduino SAMD core.\n" +
" " + os.Args[0] + " core download arduino:samd=1.6.9 # for a specific version (in this case 1.6.9).",
Args: cobra.MinimumNArgs(1),
Run: runDownloadCommand,
}
......@@ -44,7 +47,7 @@ func initDownloadCommand() *cobra.Command {
}
func runDownloadCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
logrus.Info("Executing `arduino core download`")
platformsRefs := parsePlatformReferenceArgs(args)
......@@ -55,11 +58,11 @@ func runDownloadCommand(cmd *cobra.Command, args []string) {
Architecture: platformRef.Architecture,
Version: platformRef.Version,
}
_, err := core.PlatformDownload(context.Background(), platformDownloadreq, cli.OutputProgressBar(),
cli.HTTPClientHeader)
_, err := core.PlatformDownload(context.Background(), platformDownloadreq, output.ProgressBar(),
globals.HTTPClientHeader)
if err != nil {
formatter.PrintError(err, "Error downloading "+args[i])
os.Exit(cli.ErrNetwork)
os.Exit(errorcodes.ErrNetwork)
}
}
}
......@@ -21,7 +21,10 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -35,9 +38,9 @@ func initInstallCommand() *cobra.Command {
Short: "Installs one or more cores and corresponding tool dependencies.",
Long: "Installs one or more cores and corresponding tool dependencies.",
Example: " # download the latest version of arduino SAMD core.\n" +
" " + cli.VersionInfo.Application + " core install arduino:samd\n\n" +
" " + os.Args[0] + " core install arduino:samd\n\n" +
" # download a specific version (in this case 1.6.9).\n" +
" " + cli.VersionInfo.Application + " core install arduino:samd@1.6.9",
" " + os.Args[0] + " core install arduino:samd@1.6.9",
Args: cobra.MinimumNArgs(1),
Run: runInstallCommand,
}
......@@ -45,7 +48,7 @@ func initInstallCommand() *cobra.Command {
}
func runInstallCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
logrus.Info("Executing `arduino core install`")
platformsRefs := parsePlatformReferenceArgs(args)
......@@ -57,11 +60,11 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
Architecture: platformRef.Architecture,
Version: platformRef.Version,
}
_, err := core.PlatformInstall(context.Background(), plattformInstallReq, cli.OutputProgressBar(),
cli.OutputTaskProgress(), cli.HTTPClientHeader)
_, err := core.PlatformInstall(context.Background(), plattformInstallReq, output.ProgressBar(),
output.TaskProgress(), globals.HTTPClientHeader)
if err != nil {
formatter.PrintError(err, "Error during install")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
}
......@@ -23,10 +23,11 @@ import (
"os"
"sort"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/output"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
......@@ -37,7 +38,7 @@ func initListCommand() *cobra.Command {
Use: "list",
Short: "Shows the list of installed platforms.",
Long: "Shows the list of installed platforms.",
Example: " " + cli.VersionInfo.Application + " core list",
Example: " " + os.Args[0] + " core list",
Args: cobra.NoArgs,
Run: runListCommand,
}
......@@ -50,7 +51,7 @@ var listFlags struct {
}
func runListCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
logrus.Info("Executing `arduino core list`")
resp, err := core.PlatformList(context.Background(), &rpc.PlatformListReq{
......@@ -59,11 +60,11 @@ func runListCommand(cmd *cobra.Command, args []string) {
})
if err != nil {
formatter.PrintError(err, "Error listing platforms")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
installed := resp.GetInstalledPlatform()
if installed != nil && len(installed) > 0 {
if cli.OutputJSONOrElse(installed) {
if output.JSONOrElse(installed) {
outputInstalledCores(installed)
}
}
......
......@@ -24,10 +24,11 @@ import (
"sort"
"strings"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/output"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
......@@ -38,7 +39,7 @@ func initSearchCommand() *cobra.Command {
Use: "search <keywords...>",
Short: "Search for a core in the package index.",
Long: "Search for a core in the package index using the specified keywords.",
Example: " " + cli.VersionInfo.Application + " core search MKRZero -v",
Example: " " + os.Args[0] + " core search MKRZero -v",
Args: cobra.MinimumNArgs(1),
Run: runSearchCommand,
}
......@@ -46,7 +47,7 @@ func initSearchCommand() *cobra.Command {
}
func runSearchCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
logrus.Info("Executing `arduino core search`")
arguments := strings.ToLower(strings.Join(args, " "))
......@@ -58,11 +59,11 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
})
if err != nil {
formatter.PrintError(err, "Error saerching for platforms")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
coreslist := resp.GetSearchOutput()
if cli.OutputJSONOrElse(coreslist) {
if output.JSONOrElse(coreslist) {
if len(coreslist) > 0 {
outputSearchCores(coreslist)
} else {
......
......@@ -21,10 +21,11 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/output"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
......@@ -35,14 +36,14 @@ func initUninstallCommand() *cobra.Command {
Use: "uninstall PACKAGER:ARCH ...",
Short: "Uninstalls one or more cores and corresponding tool dependencies if no more used.",
Long: "Uninstalls one or more cores and corresponding tool dependencies if no more used.",
Example: " " + cli.VersionInfo.Application + " core uninstall arduino:samd\n",
Example: " " + os.Args[0] + " core uninstall arduino:samd\n",
Args: cobra.MinimumNArgs(1),
Run: runUninstallCommand,
}
}
func runUninstallCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
logrus.Info("Executing `arduino core uninstall`")
platformsRefs := parsePlatformReferenceArgs(args)
......@@ -50,7 +51,7 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
for _, platformRef := range platformsRefs {
if platformRef.Version != "" {
formatter.PrintErrorMessage("Invalid parameter " + platformRef.String() + ": version not allowed")
os.Exit(cli.ErrBadArgument)
os.Exit(errorcodes.ErrBadArgument)
}
}
for _, platformRef := range platformsRefs {
......@@ -61,7 +62,7 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
}, output.NewTaskProgressCB())
if err != nil {
formatter.PrintError(err, "Error during uninstall")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
}
......@@ -21,7 +21,9 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -34,7 +36,7 @@ func initUpdateIndexCommand() *cobra.Command {
Use: "update-index",
Short: "Updates the index of cores.",
Long: "Updates the index of cores to the latest version.",
Example: " " + cli.VersionInfo.Application + " core update-index",
Example: " " + os.Args[0] + " core update-index",
Args: cobra.NoArgs,
Run: runUpdateIndexCommand,
}
......@@ -42,14 +44,14 @@ func initUpdateIndexCommand() *cobra.Command {
}
func runUpdateIndexCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstaceIgnorePlatformIndexErrors()
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
logrus.Info("Executing `arduino core update-index`")
_, err := commands.UpdateIndex(context.Background(), &rpc.UpdateIndexReq{
Instance: instance,
}, cli.OutputProgressBar())
}, output.ProgressBar())
if err != nil {
formatter.PrintError(err, "Error updating index")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
......@@ -21,7 +21,10 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -36,23 +39,23 @@ func initUpgradeCommand() *cobra.Command {
Long: "Upgrades one or all installed platforms to the latest version.",
Example: "" +
" # upgrade everything to the latest version\n" +
" " + cli.VersionInfo.Application + " core upgrade\n\n" +
" " + os.Args[0] + " core upgrade\n\n" +
" # upgrade arduino:samd to the latest version\n" +
" " + cli.VersionInfo.Application + " core upgrade arduino:samd",
" " + os.Args[0] + " core upgrade arduino:samd",
Run: runUpgradeCommand,
}
return upgradeCommand
}
func runUpgradeCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
logrus.Info("Executing `arduino core upgrade`")
platformsRefs := parsePlatformReferenceArgs(args)
for i, platformRef := range platformsRefs {
if platformRef.Version != "" {
formatter.PrintErrorMessage(("Invalid item " + args[i]))
os.Exit(cli.ErrBadArgument)
os.Exit(errorcodes.ErrBadArgument)
}
}
for _, platformRef := range platformsRefs {
......@@ -60,11 +63,11 @@ func runUpgradeCommand(cmd *cobra.Command, args []string) {
Instance: instance,
PlatformPackage: platformRef.Package,
Architecture: platformRef.Architecture,
}, cli.OutputProgressBar(), cli.OutputTaskProgress(),
cli.HTTPClientHeader)
}, output.ProgressBar(), output.TaskProgress(),
globals.HTTPClientHeader)
if err != nil {
formatter.PrintError(err, "Error during upgrade")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
}
......@@ -22,33 +22,32 @@ import (
"log"
"net"
"net/http"
"os"
"runtime"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/commands/daemon"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/spf13/cobra"
"google.golang.org/grpc"
)
// InitCommand initialize the command
func InitCommand() *cobra.Command {
cmd := &cobra.Command{
const (
port = ":50051"
)
// NewCommand created a new `daemon` command
func NewCommand() *cobra.Command {
return &cobra.Command{
Use: "daemon",
Short: "Run as a daemon",
Long: "Running as a daemon the initialization of cores and libraries is done only once.",
Example: " " + cli.VersionInfo.Application + " daemon",
Example: " " + os.Args[0] + " daemon",
Args: cobra.NoArgs,
Run: runDaemonCommand,
Hidden: true,
}
return cmd
}
const (
port = ":50051"
)
func runDaemonCommand(cmd *cobra.Command, args []string) {
lis, err := net.Listen("tcp", port)
if err != nil {
......@@ -56,11 +55,15 @@ func runDaemonCommand(cmd *cobra.Command, args []string) {
}
s := grpc.NewServer()
userAgentValue := fmt.Sprintf("%s/%s daemon (%s; %s; %s) Commit:%s/Build:%s", cli.VersionInfo.Application,
cli.VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), cli.VersionInfo.Commit, cli.VersionInfo.BuildDate)
userAgentValue := fmt.Sprintf("%s/%s daemon (%s; %s; %s) Commit:%s/Build:%s", globals.VersionInfo.Application,
globals.VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), globals.VersionInfo.Commit, globals.VersionInfo.BuildDate)
headers := http.Header{"User-Agent": []string{userAgentValue}}
coreServer := daemon.ArduinoCoreServerImpl{DownloaderHeaders: headers}
coreServer := daemon.ArduinoCoreServerImpl{
DownloaderHeaders: headers,
VersionString: globals.VersionInfo.VersionString,
Config: globals.Config,
}
rpc.RegisterArduinoCoreServer(s, &coreServer)
if err := s.Serve(lis); err != nil {
log.Fatalf("failed to serve: %v", err)
......
// This file is part of arduino-cli.
//
// Copyright 2019 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 errorcodes
// Error codes to be used for os.Exit().
const (
_ = iota // 0 is not a valid exit error code
ErrGeneric // 1 is the reserved "catchall" code in Unix
_ // 2 is reserved in Unix
ErrNoConfigFile
ErrBadCall
ErrNetwork
// ErrCoreConfig represents an error in the cli core config, for example some basic
// files shipped with the installation are missing, or cannot create or get basic
// directories vital for the CLI to work.
ErrCoreConfig
ErrBadArgument
)
......@@ -21,20 +21,24 @@ import (
"os"
"path/filepath"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"github.com/spf13/cobra/doc"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
var command = &cobra.Command{
var outputDir = ""
// NewCommand created a new `generatedocs` command
func NewCommand() *cobra.Command {
command := &cobra.Command{
Use: "generate-docs",
Short: "Generates bash completion and command manpages.",
Long: "Generates bash completion and command manpages.",
Example: " " + cli.VersionInfo.Application + " generate-docs bash-completions",
Example: " " + os.Args[0] + " generate-docs bash-completions",
Hidden: true,
}
command.PersistentFlags().StringVarP(&outputDir, "output-dir", "o", "",
"Directory where to save generated files. Default is './docs', the directory must exist.")
command.AddCommand(&cobra.Command{
......@@ -47,12 +51,10 @@ func InitCommand() *cobra.Command {
Args: cobra.NoArgs,
Run: generateBashCompletions,
})
command.Hidden = true
return command
}
var outputDir = ""
func generateBashCompletions(cmd *cobra.Command, args []string) {
if outputDir == "" {
outputDir = "docs/bash_completions"
......@@ -61,7 +63,7 @@ func generateBashCompletions(cmd *cobra.Command, args []string) {
err := cmd.Root().GenBashCompletionFile(filepath.Join(outputDir, "arduino"))
if err != nil {
logrus.WithError(err).Warn("Error Generating bash autocompletions")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
......@@ -78,6 +80,6 @@ func generateManPages(cmd *cobra.Command, args []string) {
err := doc.GenManTree(cmd.Root(), header, outputDir)
if err != nil {
logrus.WithError(err).Warn("Error Generating manpages")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
package globals
import (
"fmt"
"net/http"
"os"
"path/filepath"
"runtime"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/configs"
"github.com/arduino/arduino-cli/version"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
)
var (
// Debug determines whether to dump debug output to stderr or not
Debug bool
// OutputJSON is true output in JSON, false output as Text
OutputJSON bool
// HTTPClientHeader is the object that will be propagated to configure the clients inside the downloaders
HTTPClientHeader = getHTTPClientHeader()
// VersionInfo contains all info injected during build
VersionInfo = version.NewInfo(filepath.Base(os.Args[0]))
// Config FIXMEDOC
Config *configs.Configuration
// YAMLConfigFile contains the path to the config file
YAMLConfigFile string
)
func getHTTPClientHeader() http.Header {
userAgentValue := fmt.Sprintf("%s/%s (%s; %s; %s) Commit:%s/Build:%s", VersionInfo.Application,
VersionInfo.VersionString, runtime.GOARCH, runtime.GOOS, runtime.Version(), VersionInfo.Commit, VersionInfo.BuildDate)
downloaderHeaders := http.Header{"User-Agent": []string{userAgentValue}}
return downloaderHeaders
}
// InitConfigs initializes the configuration from the specified file.
func InitConfigs() {
// Start with default configuration
if conf, err := configs.NewConfiguration(); err != nil {
logrus.WithError(err).Error("Error creating default configuration")
formatter.PrintError(err, "Error creating default configuration")
os.Exit(errorcodes.ErrGeneric)
} else {
Config = conf
}
// Read configuration from global config file
logrus.Info("Checking for config file in: " + Config.ConfigFile.String())
if Config.ConfigFile.Exist() {
readConfigFrom(Config.ConfigFile)
}
if Config.IsBundledInDesktopIDE() {
logrus.Info("CLI is bundled into the IDE")
err := Config.LoadFromDesktopIDEPreferences()
if err != nil {
logrus.WithError(err).Warn("Did not manage to get config file of IDE, using default configuration")
}
} else {
logrus.Info("CLI is not bundled into the IDE")
}
// Read configuration from parent folders (project config)
if pwd, err := paths.Getwd(); err != nil {
logrus.WithError(err).Warn("Did not manage to find current path")
if path := paths.New("arduino-yaml"); path.Exist() {
readConfigFrom(path)
}
} else {
Config.Navigate(pwd)
}
// Read configuration from old configuration file if found, but output a warning.
if old := paths.New(".cli-config.yml"); old.Exist() {
logrus.Errorf("Old configuration file detected: %s.", old)
logrus.Info("The name of this file has been changed to `arduino-yaml`, please rename the file fix it.")
formatter.PrintError(
fmt.Errorf("WARNING: Old configuration file detected: %s", old),
"The name of this file has been changed to `arduino-yaml`, in a future release we will not support"+
"the old name `.cli-config.yml` anymore. Please rename the file to `arduino-yaml` to silence this warning.")
readConfigFrom(old)
}
// Read configuration from environment vars
Config.LoadFromEnv()
// Read configuration from user specified file
if YAMLConfigFile != "" {
Config.ConfigFile = paths.New(YAMLConfigFile)
readConfigFrom(Config.ConfigFile)
}
logrus.Info("Configuration set")
}
func readConfigFrom(path *paths.Path) {
logrus.Infof("Reading configuration from %s", path)
if err := Config.LoadFromYAML(path); err != nil {
logrus.WithError(err).Warnf("Could not read configuration from %s", path)
}
}
package instance
import (
"context"
"errors"
"os"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/sirupsen/logrus"
)
// CreateInstaceIgnorePlatformIndexErrors creates and return an instance of the
// Arduino Core Engine, but won't stop on platforms index loading errors.
func CreateInstaceIgnorePlatformIndexErrors() *rpc.Instance {
return initInstance().GetInstance()
}
// CreateInstance creates and return an instance of the Arduino Core engine
func CreateInstance() *rpc.Instance {
resp := initInstance()
if resp.GetPlatformsIndexErrors() != nil {
for _, err := range resp.GetPlatformsIndexErrors() {
formatter.PrintError(errors.New(err), "Error loading index")
}
formatter.PrintErrorMessage("Launch '" + os.Args[0] + " core update-index' to fix or download indexes.")
os.Exit(errorcodes.ErrGeneric)
}
return resp.GetInstance()
}
func initInstance() *rpc.InitResp {
logrus.Info("Initializing package manager")
req := packageManagerInitReq()
resp, err := commands.Init(context.Background(), req, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
if err != nil {
formatter.PrintError(err, "Error initializing package manager")
os.Exit(errorcodes.ErrGeneric)
}
if resp.GetLibrariesIndexError() != "" {
commands.UpdateLibrariesIndex(context.Background(),
&rpc.UpdateLibrariesIndexReq{Instance: resp.GetInstance()}, output.ProgressBar())
rescResp, err := commands.Rescan(context.Background(), &rpc.RescanReq{Instance: resp.GetInstance()})
if rescResp.GetLibrariesIndexError() != "" {
formatter.PrintErrorMessage("Error loading library index: " + rescResp.GetLibrariesIndexError())
os.Exit(errorcodes.ErrGeneric)
}
if err != nil {
formatter.PrintError(err, "Error loading library index")
os.Exit(errorcodes.ErrGeneric)
}
resp.LibrariesIndexError = rescResp.LibrariesIndexError
resp.PlatformsIndexErrors = rescResp.PlatformsIndexErrors
}
return resp
}
func packageManagerInitReq() *rpc.InitReq {
urls := []string{}
for _, URL := range globals.Config.BoardManagerAdditionalUrls {
urls = append(urls, URL.String())
}
conf := &rpc.Configuration{}
conf.DataDir = globals.Config.DataDir.String()
conf.DownloadsDir = globals.Config.DownloadsDir().String()
conf.BoardManagerAdditionalUrls = urls
if globals.Config.SketchbookDir != nil {
conf.SketchbookDir = globals.Config.SketchbookDir.String()
}
return &rpc.InitReq{Configuration: conf}
}
......@@ -22,7 +22,10 @@ import (
"os"
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -35,8 +38,8 @@ func initDownloadCommand() *cobra.Command {
Short: "Downloads one or more libraries without installing them.",
Long: "Downloads one or more libraries without installing them.",
Example: "" +
" " + cli.VersionInfo.Application + " lib download AudioZero # for the latest version.\n" +
" " + cli.VersionInfo.Application + " lib download AudioZero@1.0.0 # for a specific version.",
" " + os.Args[0] + " lib download AudioZero # for the latest version.\n" +
" " + os.Args[0] + " lib download AudioZero@1.0.0 # for a specific version.",
Args: cobra.MinimumNArgs(1),
Run: runDownloadCommand,
}
......@@ -44,11 +47,11 @@ func initDownloadCommand() *cobra.Command {
}
func runDownloadCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstaceIgnorePlatformIndexErrors()
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
pairs, err := librariesindex.ParseArgs(args)
if err != nil {
formatter.PrintError(err, "Arguments error")
os.Exit(cli.ErrBadArgument)
os.Exit(errorcodes.ErrBadArgument)
}
for _, library := range pairs {
libraryDownloadReq := &rpc.LibraryDownloadReq{
......@@ -56,11 +59,11 @@ func runDownloadCommand(cmd *cobra.Command, args []string) {
Name: library.Name,
Version: library.Version.String(),
}
_, err := lib.LibraryDownload(context.Background(), libraryDownloadReq, cli.OutputProgressBar(),
cli.HTTPClientHeader)
_, err := lib.LibraryDownload(context.Background(), libraryDownloadReq, output.ProgressBar(),
globals.HTTPClientHeader)
if err != nil {
formatter.PrintError(err, "Error downloading "+library.String())
os.Exit(cli.ErrNetwork)
os.Exit(errorcodes.ErrNetwork)
}
}
}
......@@ -22,7 +22,10 @@ import (
"os"
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -35,8 +38,8 @@ func initInstallCommand() *cobra.Command {
Short: "Installs one of more specified libraries into the system.",
Long: "Installs one or more specified libraries into the system.",
Example: "" +
" " + cli.VersionInfo.Application + " lib install AudioZero # for the latest version.\n" +
" " + cli.VersionInfo.Application + " lib install AudioZero@1.0.0 # for the specific version.",
" " + os.Args[0] + " lib install AudioZero # for the latest version.\n" +
" " + os.Args[0] + " lib install AudioZero@1.0.0 # for the specific version.",
Args: cobra.MinimumNArgs(1),
Run: runInstallCommand,
}
......@@ -44,11 +47,11 @@ func initInstallCommand() *cobra.Command {
}
func runInstallCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstaceIgnorePlatformIndexErrors()
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
refs, err := librariesindex.ParseArgs(args)
if err != nil {
formatter.PrintError(err, "Arguments error")
os.Exit(cli.ErrBadArgument)
os.Exit(errorcodes.ErrBadArgument)
}
for _, library := range refs {
libraryInstallReq := &rpc.LibraryInstallReq{
......@@ -56,11 +59,11 @@ func runInstallCommand(cmd *cobra.Command, args []string) {
Name: library.Name,
Version: library.Version.String(),
}
err := lib.LibraryInstall(context.Background(), libraryInstallReq, cli.OutputProgressBar(),
cli.OutputTaskProgress(), cli.HTTPClientHeader)
err := lib.LibraryInstall(context.Background(), libraryInstallReq, output.ProgressBar(),
output.TaskProgress(), globals.HTTPClientHeader)
if err != nil {
formatter.PrintError(err, "Error installing "+library.String())
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
}
......@@ -18,20 +18,22 @@
package lib
import (
"github.com/arduino/arduino-cli/cli"
"os"
"github.com/spf13/cobra"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
// NewCommand created a new `lib` command
func NewCommand() *cobra.Command {
libCommand := &cobra.Command{
Use: "lib",
Short: "Arduino commands about libraries.",
Long: "Arduino commands about libraries.",
Example: "" +
" " + cli.VersionInfo.Application + " lib install AudioZero\n" +
" " + cli.VersionInfo.Application + " lib update-index",
" " + os.Args[0] + " lib install AudioZero\n" +
" " + os.Args[0] + " lib update-index",
}
libCommand.AddCommand(initDownloadCommand())
libCommand.AddCommand(initInstallCommand())
libCommand.AddCommand(initListCommand())
......@@ -39,5 +41,6 @@ func InitCommand() *cobra.Command {
libCommand.AddCommand(initUninstallCommand())
libCommand.AddCommand(initUpgradeCommand())
libCommand.AddCommand(initUpdateIndexCommand())
return libCommand
}
......@@ -21,7 +21,9 @@ import (
"fmt"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -36,7 +38,7 @@ func initListCommand() *cobra.Command {
Use: "list",
Short: "Shows a list of all installed libraries.",
Long: "Shows a list of all installed libraries.",
Example: " " + cli.VersionInfo.Application + " lib list",
Example: " " + os.Args[0] + " lib list",
Args: cobra.NoArgs,
Run: runListCommand,
}
......@@ -51,7 +53,7 @@ var listFlags struct {
}
func runListCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstaceIgnorePlatformIndexErrors()
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
logrus.Info("Listing")
res, err := lib.LibraryList(context.Background(), &rpc.LibraryListReq{
......@@ -61,11 +63,11 @@ func runListCommand(cmd *cobra.Command, args []string) {
})
if err != nil {
formatter.PrintError(err, "Error listing Libraries")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
if len(res.GetInstalledLibrary()) > 0 {
results := res.GetInstalledLibrary()
if cli.OutputJSONOrElse(results) {
if output.JSONOrElse(results) {
if len(results) > 0 {
fmt.Println(outputListLibrary(results))
} else {
......
......@@ -24,7 +24,9 @@ import (
"sort"
"strings"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -38,7 +40,7 @@ func initSearchCommand() *cobra.Command {
Use: "search [LIBRARY_NAME]",
Short: "Searchs for one or more libraries data.",
Long: "Search for one or more libraries data (case insensitive search).",
Example: " " + cli.VersionInfo.Application + " lib search audio",
Example: " " + os.Args[0] + " lib search audio",
Args: cobra.ArbitraryArgs,
Run: runSearchCommand,
}
......@@ -51,7 +53,7 @@ var searchFlags struct {
}
func runSearchCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstaceIgnorePlatformIndexErrors()
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
logrus.Info("Executing `arduino lib search`")
searchResp, err := lib.LibrarySearch(context.Background(), &rpc.LibrarySearchReq{
Instance: instance,
......@@ -59,10 +61,10 @@ func runSearchCommand(cmd *cobra.Command, args []string) {
})
if err != nil {
formatter.PrintError(err, "Error saerching for Library")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
if cli.OutputJSONOrElse(searchResp) {
if output.JSONOrElse(searchResp) {
results := searchResp.GetLibraries()
sort.Slice(results, func(i, j int) bool {
return results[i].Name < results[j].Name
......
......@@ -22,7 +22,9 @@ import (
"os"
"github.com/arduino/arduino-cli/arduino/libraries/librariesindex"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -35,7 +37,7 @@ func initUninstallCommand() *cobra.Command {
Use: "uninstall LIBRARY_NAME(S)",
Short: "Uninstalls one or more libraries.",
Long: "Uninstalls one or more libraries.",
Example: " " + cli.VersionInfo.Application + " lib uninstall AudioZero",
Example: " " + os.Args[0] + " lib uninstall AudioZero",
Args: cobra.MinimumNArgs(1),
Run: runUninstallCommand,
}
......@@ -45,11 +47,11 @@ func initUninstallCommand() *cobra.Command {
func runUninstallCommand(cmd *cobra.Command, args []string) {
logrus.Info("Executing `arduino lib uninstall`")
instance := cli.CreateInstaceIgnorePlatformIndexErrors()
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
libRefs, err := librariesindex.ParseArgs(args)
if err != nil {
formatter.PrintError(err, "Arguments error")
os.Exit(cli.ErrBadArgument)
os.Exit(errorcodes.ErrBadArgument)
}
for _, library := range libRefs {
......@@ -57,10 +59,10 @@ func runUninstallCommand(cmd *cobra.Command, args []string) {
Instance: instance,
Name: library.Name,
Version: library.Version.String(),
}, cli.OutputTaskProgress())
}, output.TaskProgress())
if err != nil {
formatter.PrintError(err, "Error uninstalling "+library.String())
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
......
......@@ -21,7 +21,9 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -33,16 +35,16 @@ func initUpdateIndexCommand() *cobra.Command {
Use: "update-index",
Short: "Updates the libraries index.",
Long: "Updates the libraries index to the latest version.",
Example: " " + cli.VersionInfo.Application + " lib update-index",
Example: " " + os.Args[0] + " lib update-index",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
instance := cli.CreateInstaceIgnorePlatformIndexErrors()
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
err := commands.UpdateLibrariesIndex(context.Background(), &rpc.UpdateLibrariesIndexReq{
Instance: instance,
}, cli.OutputProgressBar())
}, output.ProgressBar())
if err != nil {
formatter.PrintError(err, "Error updating library index")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
},
}
......
......@@ -20,7 +20,10 @@ package lib
import (
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/cli/output"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
......@@ -35,7 +38,7 @@ func initUpgradeCommand() *cobra.Command {
Short: "Upgrades installed libraries.",
Long: "This command ungrades all installed libraries to the latest available version." +
"To upgrade a single library use the 'install' command.",
Example: " " + cli.VersionInfo.Application + " lib upgrade",
Example: " " + os.Args[0] + " lib upgrade",
Args: cobra.NoArgs,
Run: runUpgradeCommand,
}
......@@ -43,14 +46,14 @@ func initUpgradeCommand() *cobra.Command {
}
func runUpgradeCommand(cmd *cobra.Command, args []string) {
instance := cli.CreateInstaceIgnorePlatformIndexErrors()
instance := instance.CreateInstaceIgnorePlatformIndexErrors()
err := lib.LibraryUpgradeAll(context.Background(), &rpc.LibraryUpgradeAllReq{
Instance: instance,
}, cli.OutputProgressBar(), cli.OutputTaskProgress(), cli.HTTPClientHeader)
}, output.ProgressBar(), output.TaskProgress(), globals.HTTPClientHeader)
if err != nil {
formatter.PrintError(err, "Error upgrading libraries")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
logrus.Info("Done")
......
......@@ -15,51 +15,56 @@
// a commercial license, send an email to license@arduino.cc.
//
package cli
package output
import (
"encoding/json"
"fmt"
"os"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/output"
rpc "github.com/arduino/arduino-cli/rpc/commands"
colorable "github.com/mattn/go-colorable"
)
// OutputJSONOrElse outputs the JSON encoding of v if the JSON output format has been
// TODO: Feed text output into colorable stdOut
var _ = colorable.NewColorableStdout()
// JSONOrElse outputs the JSON encoding of v if the JSON output format has been
// selected by the user and returns false. Otherwise no output is produced and the
// function returns true.
func OutputJSONOrElse(v interface{}) bool {
if !GlobalFlags.OutputJSON {
func JSONOrElse(v interface{}) bool {
if !globals.OutputJSON {
return true
}
d, err := json.MarshalIndent(v, "", " ")
if err != nil {
formatter.PrintError(err, "Error during JSON encoding of the output")
os.Exit(ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
fmt.Print(string(d))
return false
}
// OutputProgressBar returns a DownloadProgressCB that prints a progress bar.
// ProgressBar returns a DownloadProgressCB that prints a progress bar.
// If JSON output format has been selected, the callback outputs nothing.
func OutputProgressBar() commands.DownloadProgressCB {
if !GlobalFlags.OutputJSON {
return output.NewDownloadProgressBarCB()
func ProgressBar() commands.DownloadProgressCB {
if !globals.OutputJSON {
return NewDownloadProgressBarCB()
}
return func(curr *rpc.DownloadProgress) {
// XXX: Output progress in JSON?
}
}
// OutputTaskProgress returns a TaskProgressCB that prints the task progress.
// TaskProgress returns a TaskProgressCB that prints the task progress.
// If JSON output format has been selected, the callback outputs nothing.
func OutputTaskProgress() commands.TaskProgressCB {
if !GlobalFlags.OutputJSON {
return output.NewTaskProgressCB()
func TaskProgress() commands.TaskProgressCB {
if !globals.OutputJSON {
return NewTaskProgressCB()
}
return func(curr *rpc.TaskProgress) {
// XXX: Output progress in JSON?
......
/*
* 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 root
import (
"fmt"
"io/ioutil"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/board"
"github.com/arduino/arduino-cli/cli/compile"
"github.com/arduino/arduino-cli/cli/config"
"github.com/arduino/arduino-cli/cli/core"
"github.com/arduino/arduino-cli/cli/daemon"
"github.com/arduino/arduino-cli/cli/generatedocs"
"github.com/arduino/arduino-cli/cli/lib"
"github.com/arduino/arduino-cli/cli/sketch"
"github.com/arduino/arduino-cli/cli/upload"
"github.com/arduino/arduino-cli/cli/version"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/arduino/arduino-cli/configs"
"github.com/arduino/go-paths-helper"
"github.com/mattn/go-colorable"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh/terminal"
)
// Init prepares the cobra root command.
func Init() *cobra.Command {
command := &cobra.Command{
Use: "arduino-cli",
Short: "Arduino CLI.",
Long: "Arduino Command Line Interface (arduino-cli).",
Example: " " + cli.VersionInfo.Application + " <command> [flags...]",
PersistentPreRun: preRun,
}
command.PersistentFlags().BoolVar(&cli.GlobalFlags.Debug, "debug", false, "Enables debug output (super verbose, used to debug the CLI).")
command.PersistentFlags().StringVar(&outputFormat, "format", "text", "The output format, can be [text|json].")
command.PersistentFlags().StringVar(&yamlConfigFile, "config-file", "", "The custom config file (if not specified the default will be used).")
command.AddCommand(board.InitCommand())
command.AddCommand(compile.InitCommand())
command.AddCommand(config.InitCommand())
command.AddCommand(core.InitCommand())
command.AddCommand(daemon.InitCommand())
command.AddCommand(generatedocs.InitCommand())
command.AddCommand(lib.InitCommand())
// command.AddCommand(login.InitCommand())
// command.AddCommand(logout.InitCommand())
command.AddCommand(sketch.InitCommand())
command.AddCommand(upload.InitCommand())
// command.AddCommand(validate.InitCommand())
command.AddCommand(version.InitCommand())
return command
}
var outputFormat string
var yamlConfigFile string
func preRun(cmd *cobra.Command, args []string) {
// Reset logrus if debug flag changed.
if !cli.GlobalFlags.Debug {
// Discard logrus output if no debug.
logrus.SetOutput(ioutil.Discard)
} else {
// Else print on stderr.
// Workaround to get colored output on windows
if terminal.IsTerminal(int(os.Stdout.Fd())) {
logrus.SetFormatter(&logrus.TextFormatter{ForceColors: true})
}
logrus.SetOutput(colorable.NewColorableStdout())
cli.ErrLogrus.Out = colorable.NewColorableStderr()
formatter.SetLogger(cli.ErrLogrus)
}
initConfigs()
logrus.Info(cli.VersionInfo.Application + "-" + cli.VersionInfo.VersionString)
logrus.Info("Starting root command preparation (`arduino`)")
switch outputFormat {
case "text":
formatter.SetFormatter("text")
cli.GlobalFlags.OutputJSON = false
case "json":
formatter.SetFormatter("json")
cli.GlobalFlags.OutputJSON = true
default:
formatter.PrintErrorMessage("Invalid output format: " + outputFormat)
os.Exit(cli.ErrBadCall)
}
logrus.Info("Formatter set")
if !formatter.IsCurrentFormat("text") {
cmd.SetHelpFunc(func(cmd *cobra.Command, args []string) {
logrus.Warn("Calling help on JSON format")
formatter.PrintErrorMessage("Invalid Call : should show Help, but it is available only in TEXT mode.")
os.Exit(cli.ErrBadCall)
})
}
}
// initConfigs initializes the configuration from the specified file.
func initConfigs() {
// Start with default configuration
if conf, err := configs.NewConfiguration(); err != nil {
logrus.WithError(err).Error("Error creating default configuration")
formatter.PrintError(err, "Error creating default configuration")
os.Exit(cli.ErrGeneric)
} else {
cli.Config = conf
}
// Read configuration from global config file
logrus.Info("Checking for config file in: " + cli.Config.ConfigFile.String())
if cli.Config.ConfigFile.Exist() {
readConfigFrom(cli.Config.ConfigFile)
}
if cli.Config.IsBundledInDesktopIDE() {
logrus.Info("CLI is bundled into the IDE")
err := cli.Config.LoadFromDesktopIDEPreferences()
if err != nil {
logrus.WithError(err).Warn("Did not manage to get config file of IDE, using default configuration")
}
} else {
logrus.Info("CLI is not bundled into the IDE")
}
// Read configuration from parent folders (project config)
if pwd, err := paths.Getwd(); err != nil {
logrus.WithError(err).Warn("Did not manage to find current path")
if path := paths.New("arduino-cli.yaml"); path.Exist() {
readConfigFrom(path)
}
} else {
cli.Config.Navigate(pwd)
}
// Read configuration from old configuration file if found, but output a warning.
if old := paths.New(".cli-config.yml"); old.Exist() {
logrus.Errorf("Old configuration file detected: %s.", old)
logrus.Info("The name of this file has been changed to `arduino-cli.yaml`, please rename the file fix it.")
formatter.PrintError(
fmt.Errorf("WARNING: Old configuration file detected: %s", old),
"The name of this file has been changed to `arduino-cli.yaml`, in a future release we will not support"+
"the old name `.cli-config.yml` anymore. Please rename the file to `arduino-cli.yaml` to silence this warning.")
readConfigFrom(old)
}
// Read configuration from environment vars
cli.Config.LoadFromEnv()
// Read configuration from user specified file
if yamlConfigFile != "" {
cli.Config.ConfigFile = paths.New(yamlConfigFile)
readConfigFrom(cli.Config.ConfigFile)
}
logrus.Info("Configuration set")
}
func readConfigFrom(path *paths.Path) {
logrus.Infof("Reading configuration from %s", path)
if err := cli.Config.LoadFromYAML(path); err != nil {
logrus.WithError(err).Warnf("Could not read configuration from %s", path)
}
}
......@@ -20,7 +20,8 @@ package sketch
import (
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/common/formatter"
"github.com/spf13/cobra"
)
......@@ -30,7 +31,7 @@ func initNewCommand() *cobra.Command {
Use: "new",
Short: "Create a new Sketch",
Long: "Create a new Sketch",
Example: " " + cli.VersionInfo.Application + " sketch new MultiBlinker",
Example: " " + os.Args[0] + " sketch new MultiBlinker",
Args: cobra.ExactArgs(1),
Run: runNewCommand,
}
......@@ -46,16 +47,16 @@ void loop() {
`)
func runNewCommand(cmd *cobra.Command, args []string) {
sketchDir := cli.Config.SketchbookDir.Join(args[0])
sketchDir := globals.Config.SketchbookDir.Join(args[0])
if err := sketchDir.MkdirAll(); err != nil {
formatter.PrintError(err, "Could not create sketch directory.")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
sketchFile := sketchDir.Join(args[0] + ".ino")
if err := sketchFile.WriteFile(emptySketch); err != nil {
formatter.PrintError(err, "Error creating sketch.")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
formatter.Print("Sketch created in: " + sketchDir.String())
......
......@@ -18,19 +18,21 @@
package sketch
import (
"github.com/arduino/arduino-cli/cli"
"os"
"github.com/spf13/cobra"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
sketchCommand := &cobra.Command{
// NewCommand created a new `sketch` command
func NewCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "sketch",
Short: "Arduino CLI Sketch Commands.",
Long: "Arduino CLI Sketch Commands.",
Example: " " + cli.VersionInfo.Application + " sketch new MySketch",
Example: " " + os.Args[0] + " sketch new MySketch",
}
sketchCommand.AddCommand(initNewCommand())
//sketchCommand.AddCommand(initSyncCommand())
return sketchCommand
cmd.AddCommand(initNewCommand())
return cmd
}
......@@ -21,76 +21,80 @@ import (
"context"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/cli/instance"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/common/formatter"
rpc "github.com/arduino/arduino-cli/rpc/commands"
"github.com/arduino/go-paths-helper"
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
var (
fqbn string
port string
verbose bool
verify bool
importFile string
)
// NewCommand created a new `upload` command
func NewCommand() *cobra.Command {
uploadCommand := &cobra.Command{
Use: "upload",
Short: "Upload Arduino sketches.",
Long: "Upload Arduino sketches.",
Example: " " + cli.VersionInfo.Application + " upload /home/user/Arduino/MySketch",
Example: " " + os.Args[0] + " upload /home/user/Arduino/MySketch",
Args: cobra.MaximumNArgs(1),
Run: run,
}
uploadCommand.Flags().StringVarP(
&flags.fqbn, "fqbn", "b", "",
"Fully Qualified Board Name, e.g.: arduino:avr:uno")
uploadCommand.Flags().StringVarP(
&flags.port, "port", "p", "",
"Upload port, e.g.: COM10 or /dev/ttyACM0")
uploadCommand.Flags().StringVarP(
&flags.importFile, "input", "i", "",
"Input file to be uploaded.")
uploadCommand.Flags().BoolVarP(
&flags.verify, "verify", "t", false,
"Verify uploaded binary after the upload.")
uploadCommand.Flags().BoolVarP(
&flags.verbose, "verbose", "v", false,
"Optional, turns on verbose mode.")
return uploadCommand
}
var flags struct {
fqbn string
port string
verbose bool
verify bool
importFile string
uploadCommand.Flags().StringVarP(&fqbn, "fqbn", "b", "", "Fully Qualified Board Name, e.g.: arduino:avr:uno")
uploadCommand.Flags().StringVarP(&port, "port", "p", "", "Upload port, e.g.: COM10 or /dev/ttyACM0")
uploadCommand.Flags().StringVarP(&importFile, "input", "i", "", "Input file to be uploaded.")
uploadCommand.Flags().BoolVarP(&verify, "verify", "t", false, "Verify uploaded binary after the upload.")
uploadCommand.Flags().BoolVarP(&verbose, "verbose", "v", false, "Optional, turns on verbose mode.")
return uploadCommand
}
func run(command *cobra.Command, args []string) {
instance := cli.CreateInstance()
instance := instance.CreateInstance()
var path *paths.Path
if len(args) > 0 {
path = paths.New(args[0])
}
sketchPath := cli.InitSketchPath(path)
sketchPath := initSketchPath(path)
uploadRes, err := upload.Upload(context.Background(), &rpc.UploadReq{
_, err := upload.Upload(context.Background(), &rpc.UploadReq{
Instance: instance,
Fqbn: flags.fqbn,
Fqbn: fqbn,
SketchPath: sketchPath.String(),
Port: flags.port,
Verbose: flags.verbose,
Verify: flags.verify,
ImportFile: flags.importFile,
Port: port,
Verbose: verbose,
Verify: verify,
ImportFile: importFile,
}, os.Stdout, os.Stderr)
if err == nil {
outputUploadResp(uploadRes)
} else {
if err != nil {
formatter.PrintError(err, "Error during Upload")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
func outputUploadResp(details *rpc.UploadResp) {
// initSketchPath returns the current working directory
func initSketchPath(sketchPath *paths.Path) *paths.Path {
if sketchPath != nil {
return sketchPath
}
wd, err := paths.Getwd()
if err != nil {
formatter.PrintError(err, "Couldn't get current working directory")
os.Exit(errorcodes.ErrGeneric)
}
logrus.Infof("Reading sketch from dir: %s", wd)
return wd
}
......@@ -19,39 +19,27 @@ package version
import (
"fmt"
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/globals"
"github.com/arduino/arduino-cli/cli/output"
"github.com/spf13/cobra"
)
// InitCommand prepares the command.
func InitCommand() *cobra.Command {
versionCommand := &cobra.Command{
// NewCommand created a new `version` command
func NewCommand() *cobra.Command {
return &cobra.Command{
Use: "version",
Short: "Shows version number of arduino CLI.",
Long: "Shows version number of arduino CLI which is installed on your system.",
Example: " " + cli.VersionInfo.Application + " version",
Example: " " + os.Args[0] + " version",
Args: cobra.NoArgs,
Run: run,
}
return versionCommand
}
type versionOutput struct {
Command string `json:"command"`
Version string `json:"version"`
Commit string `json:"commit"`
BuildDate string `json:"build_date"`
}
func run(cmd *cobra.Command, args []string) {
res := &versionOutput{
Command: cmd.Parent().Name(),
Version: cli.VersionInfo.VersionString,
Commit: cli.VersionInfo.Commit,
BuildDate: cli.VersionInfo.BuildDate.String(),
}
if cli.OutputJSONOrElse(res) {
fmt.Printf("%s\n", cli.VersionInfo)
if output.JSONOrElse(globals.VersionInfo) {
fmt.Printf("%s\n", globals.VersionInfo)
}
}
......@@ -29,8 +29,8 @@ import (
"github.com/arduino/arduino-cli/arduino/cores"
"github.com/arduino/arduino-cli/arduino/cores/packagemanager"
"github.com/arduino/arduino-cli/arduino/sketches"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/commands"
"github.com/arduino/arduino-cli/configs"
"github.com/arduino/arduino-cli/legacy/builder"
"github.com/arduino/arduino-cli/legacy/builder/i18n"
"github.com/arduino/arduino-cli/legacy/builder/types"
......@@ -41,7 +41,7 @@ import (
)
// Compile FIXMEDOC
func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errStream io.Writer) (*rpc.CompileResp, error) {
func Compile(ctx context.Context, req *rpc.CompileReq, outStream, errStream io.Writer, config *configs.Configuration, debug bool) (*rpc.CompileResp, error) {
pm := commands.GetPackageManager(req)
if pm == nil {
return nil, errors.New("invalid instance")
......@@ -88,20 +88,20 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errS
builderCtx.SketchLocation = sketch.FullPath
// FIXME: This will be redundant when arduino-builder will be part of the cli
if packagesDir, err := cli.Config.HardwareDirectories(); err == nil {
if packagesDir, err := config.HardwareDirectories(); err == nil {
builderCtx.HardwareDirs = packagesDir
} else {
return nil, fmt.Errorf("cannot get hardware directories: %s", err)
}
if toolsDir, err := cli.Config.BundleToolsDirectories(); err == nil {
if toolsDir, err := config.BundleToolsDirectories(); err == nil {
builderCtx.ToolsDirs = toolsDir
} else {
return nil, fmt.Errorf("cannot get bundled tools directories: %s", err)
}
builderCtx.OtherLibrariesDirs = paths.NewPathList()
builderCtx.OtherLibrariesDirs.Add(cli.Config.LibrariesDir())
builderCtx.OtherLibrariesDirs.Add(config.LibrariesDir())
if req.GetBuildPath() != "" {
builderCtx.BuildPath = paths.New(req.GetBuildPath())
......@@ -118,7 +118,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errS
builderCtx.USBVidPid = req.GetVidPid()
builderCtx.WarningsLevel = req.GetWarnings()
if cli.GlobalFlags.Debug {
if debug {
builderCtx.DebugLevel = 100
} else {
builderCtx.DebugLevel = 5
......@@ -138,7 +138,7 @@ func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errS
builderCtx.ArduinoAPIVersion = "10607"
// Check if Arduino IDE is installed and get it's libraries location.
preferencesTxt := cli.Config.DataDir.Join("preferences.txt")
preferencesTxt := config.DataDir.Join("preferences.txt")
ideProperties, err := properties.LoadFromPath(preferencesTxt)
if err == nil {
lastIdeSubProperties := ideProperties.SubTree("last").SubTree("ide")
......
......@@ -25,19 +25,21 @@ import (
"io"
"net/http"
"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"
"github.com/arduino/arduino-cli/commands/core"
"github.com/arduino/arduino-cli/commands/lib"
"github.com/arduino/arduino-cli/commands/upload"
"github.com/arduino/arduino-cli/configs"
rpc "github.com/arduino/arduino-cli/rpc/commands"
)
// ArduinoCoreServerImpl FIXMEDOC
type ArduinoCoreServerImpl struct {
DownloaderHeaders http.Header
VersionString string
Config *configs.Configuration
}
// BoardDetails FIXMEDOC
......@@ -115,7 +117,7 @@ func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_In
// Version FIXMEDOC
func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq) (*rpc.VersionResp, error) {
return &rpc.VersionResp{Version: cli.VersionInfo.VersionString}, nil
return &rpc.VersionResp{Version: s.VersionString}, nil
}
// Compile FIXMEDOC
......@@ -124,7 +126,8 @@ func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoC
stream.Context(), req,
feedStream(func(data []byte) { stream.Send(&rpc.CompileResp{OutStream: data}) }),
feedStream(func(data []byte) { stream.Send(&rpc.CompileResp{ErrStream: data}) }),
)
s.Config,
false) // set debug to false
if err != nil {
return err
}
......
......@@ -44,6 +44,7 @@ require (
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2
golang.org/x/net v0.0.0-20190311183353-d8887717615a
golang.org/x/text v0.3.0
google.golang.org/appengine v1.4.0 // indirect
google.golang.org/genproto v0.0.0-20190327125643-d831d65fe17d // indirect
google.golang.org/grpc v1.21.1
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
......
......@@ -125,31 +125,48 @@ go.bug.st/serial.v1 v0.0.0-20180827123349-5f7892a7bb45/go.mod h1:dRSl/CVCTf56CkX
golang.org/x/crypto v0.0.0-20181203042331-505ab145d0a9/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4 h1:HuIa8hRrWRSrqYzx1qI49NNxhdi2PrY7gxVSq1JjLDc=
golang.org/x/crypto v0.0.0-20190701094942-4def268fd1a4/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422 h1:QzoH/1pFpZguR8NrRHLcO6jKqfv2zpuSqZLgdm7ZmjI=
golang.org/x/lint v0.0.0-20190409202823-959b441ac422/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7 h1:rTIdg5QFRR7XCaK4LCjBiPbx8j4DQRpdYMnGn/bJUEU=
golang.org/x/net v0.0.0-20190628185345-da137c7871d7/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20181205085412-a5c9d58dba9a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894 h1:Cz4ceDQGXuKRnVBDTS23GTn/pU5OE2C0WrNTOYK1Uuc=
golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542 h1:6ZQFf1D2YYDDI7eSwW8adlkkavTB9sw5I24FVtEvNUQ=
golang.org/x/sys v0.0.0-20190710143415-6ec70d6a5542/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190328211700-ab21143f2384/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190710184609-286818132824 h1:dOGf5KG5e5tnConXcTAnHv2YgmYJtrYjN9b1cMC21TY=
golang.org/x/tools v0.0.0-20190710184609-286818132824/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
......
......@@ -21,14 +21,13 @@ import (
"os"
"github.com/arduino/arduino-cli/cli"
"github.com/arduino/arduino-cli/cli/root"
"github.com/arduino/arduino-cli/cli/errorcodes"
"github.com/arduino/arduino-cli/common/formatter"
)
func main() {
cmd := root.Init()
if err := cmd.Execute(); err != nil {
if err := cli.ArduinoCli.Execute(); err != nil {
formatter.PrintError(err, "Bad exit.")
os.Exit(cli.ErrGeneric)
os.Exit(errorcodes.ErrGeneric)
}
}
/*
* 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 (
colorable "github.com/mattn/go-colorable"
)
// TODO: Feed text output into colorable stdOut
var _ = colorable.NewColorableStdout()
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