diff --git a/.golangci.yml b/.golangci.yml deleted file mode 100644 index fd1caa762db..00000000000 --- a/.golangci.yml +++ /dev/null @@ -1,40 +0,0 @@ -run: - skip-dirs: - - legacy - -linters-settings: - govet: - check-shadowing: true - golint: - min-confidence: 0 - gocyclo: - min-complexity: 13 # Should be 10 but was brought to 13 to speed up the development - maligned: - suggest-new: true - dupl: - threshold: 100 - goconst: - min-len: 2 - min-occurrences: 2 - lll: - line-length: 160 - - misspell: - locale: US - -linters: - enable-all: true - disable: - - goimports - - gocritic - - gochecknoglobals - - gosec - - deadcode - - dupl - - errcheck - - goconst - - gocyclo - - govet - - maligned - - megacheck - - unparam diff --git a/.travis.yml b/.travis.yml index f96024ab445..14d34d7f1c1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,23 +9,21 @@ env: # Anything in before_script that returns a nonzero exit code will flunk the # build and immediately stop. It's sorta like having set -e enabled in bash. # Make sure golangci-lint is vendored. -before_install: - - curl -sfL https://install.goreleaser.com/github.com/golangci/golangci-lint.sh | bash -s -- -b $GOPATH/bin v1.16.0 +install: - curl -sL https://taskfile.dev/install.sh | sh - -install: true + - go get github.com/golangci/govet + - go get golang.org/x/lint/golint script: - # Check if the code is formatted - - $(exit $(go fmt ./... | wc -l)) - # Run linter - - golangci-lint run + # Check if the code is formatted and run linter + - ./bin/task check # Build and test - ./bin/task build - ./bin/task test - ./bin/task test-legacy after_success: - - bash <(curl -s https://codecov.io/bash) -cF unittests,integration + - bash <(curl -s https://codecov.io/bash) -cF unit -f '*_unit.txt' + - bash <(curl -s https://codecov.io/bash) -cF integ -f '*_integ.txt' diff --git a/README.md b/README.md index e282ed85425..7e8756a278e 100644 --- a/README.md +++ b/README.md @@ -344,9 +344,13 @@ Currently Unit and Integration test are available for launch in 2 ways: ``` * build: Build the project -* test: Run the full testsuite +* check: Check fmt and lint, `legacy` will be skipped +* check-legacy: Check fmt and lint for the `legacy` package +* test: Run the full testsuite, `legacy` will be skipped * test-integration: Run integration tests only +* test-legacy: Run tests for the `legacy` package * test-unit: Run unit tests only +* test-unit-race: Run unit tests only with race condition detection ``` For Example to launch unit tests only run: `task test-unit` \ No newline at end of file diff --git a/Taskfile.yml b/Taskfile.yml index aea81983b6a..b7ecbb9212d 100644 --- a/Taskfile.yml +++ b/Taskfile.yml @@ -27,8 +27,28 @@ tasks: cmds: - go test {{ default "-v" .GOFLAGS }} ./legacy/... + test-unit-race: + desc: Run unit tests only with race condition detection + cmds: + - go test -short -race {{ default "-v" .GOFLAGS }} -coverprofile=coverage_race_unit.txt {{ default .DEFAULT_TARGETS .TARGETS }} + + check: + desc: Check fmt and lint, `legacy` will be skipped + cmds: + - test -z $(go fmt {{ default .DEFAULT_TARGETS .TARGETS }}) + - go vet {{ default .DEFAULT_TARGETS .TARGETS }} + - golint {{.GOLINTFLAGS}} {{ default .DEFAULT_TARGETS .TARGETS }} + + check-legacy: + desc: Check fmt and lint for the `legacy` package + cmds: + - test -z $(go fmt ./legacy/...) + - go vet ./legacy/... + vars: - DEFAULT_TARGETS: "./arduino/... ./auth/... ./cli/... ./commands/... ./executils/... ./version/..." + # all modules of this project except for "legacy/..." module + DEFAULT_TARGETS: + sh: echo `go list ./... | grep -v legacy | tr '\n' ' '` # build vars VERSIONSTRING: "0.3.6-alpha.preview" @@ -39,9 +59,12 @@ vars: -X github.com/arduino/arduino-cli/version.commit={{.COMMIT}}' # test vars - GOFLAGS: "-timeout 5m -v -coverpkg=./... -covermode=atomic" + GOFLAGS: "-timeout 10m -v -coverpkg=./... -covermode=atomic" TEST_VERSIONSTRING: "0.0.0-test.preview" TEST_COMMIT: "deadbeef" TEST_LDFLAGS: > -ldflags '-X github.com/arduino/arduino-cli/version.versionString={{.TEST_VERSIONSTRING}} - -X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}' \ No newline at end of file + -X github.com/arduino/arduino-cli/version.commit={{.TEST_COMMIT}}' + + # check-lint vars + GOLINTFLAGS: "-min_confidence 0.8 -set_exit_status" \ No newline at end of file diff --git a/arduino/cores/packagemanager/loader.go b/arduino/cores/packagemanager/loader.go index 488e6b4a9f7..0aa4ddb8185 100644 --- a/arduino/cores/packagemanager/loader.go +++ b/arduino/cores/packagemanager/loader.go @@ -27,7 +27,7 @@ import ( "github.com/arduino/arduino-cli/configs" "github.com/arduino/go-paths-helper" properties "github.com/arduino/go-properties-orderedmap" - "go.bug.st/relaxed-semver" + semver "go.bug.st/relaxed-semver" ) // LoadHardware read all plaforms from the configured paths @@ -361,6 +361,7 @@ func (pm *PackageManager) loadToolReleasesFromTool(tool *cores.Tool, toolPath *p return nil } +// LoadToolsFromBundleDirectories FIXMEDOC func (pm *PackageManager) LoadToolsFromBundleDirectories(dirs paths.PathList) error { for _, dir := range dirs { if err := pm.LoadToolsFromBundleDirectory(dir); err != nil { @@ -370,6 +371,7 @@ func (pm *PackageManager) LoadToolsFromBundleDirectories(dirs paths.PathList) er return nil } +// LoadToolsFromBundleDirectory FIXMEDOC func (pm *PackageManager) LoadToolsFromBundleDirectory(toolsPath *paths.Path) error { pm.Log.Infof("Loading tools from bundle dir: %s", toolsPath) diff --git a/arduino/cores/packagemanager/package_manager.go b/arduino/cores/packagemanager/package_manager.go index 3e50c3a3cbf..3654121d486 100644 --- a/arduino/cores/packagemanager/package_manager.go +++ b/arduino/cores/packagemanager/package_manager.go @@ -59,14 +59,17 @@ func NewPackageManager(indexDir, packagesDir, downloadDir, tempDir *paths.Path) } } +// Clear FIXMEDOC func (pm *PackageManager) Clear() { pm.packages = cores.NewPackages() } +// GetPackages FIXMEDOC func (pm *PackageManager) GetPackages() *cores.Packages { return pm.packages } +// FindPlatformReleaseProvidingBoardsWithVidPid FIXMEDOC func (pm *PackageManager) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid string) []*cores.PlatformRelease { res := []*cores.PlatformRelease{} for _, targetPackage := range pm.packages.Packages { @@ -86,6 +89,7 @@ func (pm *PackageManager) FindPlatformReleaseProvidingBoardsWithVidPid(vid, pid return res } +// FindBoardsWithVidPid FIXMEDOC func (pm *PackageManager) FindBoardsWithVidPid(vid, pid string) []*cores.Board { res := []*cores.Board{} for _, targetPackage := range pm.packages.Packages { @@ -102,6 +106,7 @@ func (pm *PackageManager) FindBoardsWithVidPid(vid, pid string) []*cores.Board { return res } +// FindBoardsWithID FIXMEDOC func (pm *PackageManager) FindBoardsWithID(id string) []*cores.Board { res := []*cores.Board{} for _, targetPackage := range pm.packages.Packages { @@ -290,6 +295,7 @@ func (ta *ToolActions) IsInstalled() (bool, error) { return false, nil } +// Release FIXMEDOC func (ta *ToolActions) Release(version *semver.RelaxedVersion) *ToolReleaseActions { if ta.forwardError != nil { return &ToolReleaseActions{forwardError: ta.forwardError} @@ -310,6 +316,7 @@ type ToolReleaseActions struct { forwardError error } +// Get FIXMEDOC func (tr *ToolReleaseActions) Get() (*cores.ToolRelease, error) { if tr.forwardError != nil { return nil, tr.forwardError @@ -340,6 +347,7 @@ func (pm *PackageManager) GetInstalledPlatformRelease(platform *cores.Platform) return best } +// GetAllInstalledToolsReleases FIXMEDOC func (pm *PackageManager) GetAllInstalledToolsReleases() []*cores.ToolRelease { tools := []*cores.ToolRelease{} for _, targetPackage := range pm.packages.Packages { @@ -384,6 +392,7 @@ func (pm *PackageManager) InstalledBoards() []*cores.Board { return boards } +// FindToolsRequiredForBoard FIXMEDOC func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*cores.ToolRelease, error) { pm.Log.Infof("Searching tools required for board %s", board) @@ -421,6 +430,7 @@ func (pm *PackageManager) FindToolsRequiredForBoard(board *cores.Board) ([]*core return requiredTools, nil } +// FindToolDependency FIXMEDOC func (pm *PackageManager) FindToolDependency(dep *cores.ToolDependency) *cores.ToolRelease { toolRelease, err := pm.Package(dep.ToolPackager).Tool(dep.ToolName).Release(dep.ToolVersion).Get() if err != nil { diff --git a/arduino/libraries/libraries.go b/arduino/libraries/libraries.go index a8799fbb1b9..b3b4ec7980c 100644 --- a/arduino/libraries/libraries.go +++ b/arduino/libraries/libraries.go @@ -26,8 +26,13 @@ import ( semver "go.bug.st/relaxed-semver" ) +// MandatoryProperties FIXMEDOC var MandatoryProperties = []string{"name", "version", "author", "maintainer"} + +// OptionalProperties FIXMEDOC var OptionalProperties = []string{"sentence", "paragraph", "url"} + +// ValidCategories FIXMEDOC var ValidCategories = map[string]bool{ "Display": true, "Communication": true, diff --git a/cli/cli.go b/cli/cli.go index 54e028e0f1b..cafc6b87a22 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -58,6 +58,7 @@ 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 @@ -70,6 +71,7 @@ var GlobalFlags struct { OutputJSON bool // true output in JSON, false output as Text } +// Config FIXMEDOC var Config *configs.Configuration func packageManagerInitReq() *rpc.InitReq { @@ -96,6 +98,7 @@ func getHTTPClientHeader() http.Header { return downloaderHeaders } +// InitInstance FIXMEDOC func InitInstance() *rpc.InitResp { logrus.Info("Initializing package manager") req := packageManagerInitReq() diff --git a/commands/board/attach.go b/commands/board/attach.go index 329302070fb..bf8cb7a902c 100644 --- a/commands/board/attach.go +++ b/commands/board/attach.go @@ -34,6 +34,7 @@ import ( paths "github.com/arduino/go-paths-helper" ) +// Attach FIXMEDOC func Attach(ctx context.Context, req *rpc.BoardAttachReq, taskCB commands.TaskProgressCB) (*rpc.BoardAttachResp, error) { pm := commands.GetPackageManager(req) diff --git a/commands/board/details.go b/commands/board/details.go index 9837c8c9c55..e350687330c 100644 --- a/commands/board/details.go +++ b/commands/board/details.go @@ -27,6 +27,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// Details FIXMEDOC func Details(ctx context.Context, req *rpc.BoardDetailsReq) (*rpc.BoardDetailsResp, error) { pm := commands.GetPackageManager(req) if pm == nil { diff --git a/commands/board/list.go b/commands/board/list.go index a4747c07210..389af5805ee 100644 --- a/commands/board/list.go +++ b/commands/board/list.go @@ -26,6 +26,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// List FIXMEDOC func List(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp, error) { pm := commands.GetPackageManager(req) if pm == nil { diff --git a/commands/board/listall.go b/commands/board/listall.go index 48343458ad5..f488ac0d3c8 100644 --- a/commands/board/listall.go +++ b/commands/board/listall.go @@ -26,6 +26,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// ListAll FIXMEDOC func ListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllResp, error) { pm := commands.GetPackageManager(req) if pm == nil { diff --git a/commands/compile/compile.go b/commands/compile/compile.go index d4635393963..bbb9eb2a607 100644 --- a/commands/compile/compile.go +++ b/commands/compile/compile.go @@ -40,6 +40,7 @@ import ( "github.com/sirupsen/logrus" ) +// Compile FIXMEDOC func Compile(ctx context.Context, req *rpc.CompileReq, outStream io.Writer, errStream io.Writer) (*rpc.CompileResp, error) { pm := commands.GetPackageManager(req) if pm == nil { diff --git a/commands/core/download.go b/commands/core/download.go index 86e389b20f8..787dc0b23ad 100644 --- a/commands/core/download.go +++ b/commands/core/download.go @@ -29,6 +29,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// PlatformDownload FIXMEDOC func PlatformDownload(ctx context.Context, req *rpc.PlatformDownloadReq, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) (*rpc.PlatformDownloadResp, error) { pm := commands.GetPackageManager(req) diff --git a/commands/core/install.go b/commands/core/install.go index d418aafa3ec..876162aae61 100644 --- a/commands/core/install.go +++ b/commands/core/install.go @@ -29,6 +29,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// PlatformInstall FIXMEDOC func PlatformInstall(ctx context.Context, req *rpc.PlatformInstallReq, downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) (*rpc.PlatformInstallResp, error) { diff --git a/commands/core/list.go b/commands/core/list.go index 75992641650..591a1819d50 100644 --- a/commands/core/list.go +++ b/commands/core/list.go @@ -25,6 +25,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// PlatformList FIXMEDOC func PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformListResp, error) { pm := commands.GetPackageManager(req) if pm == nil { diff --git a/commands/core/search.go b/commands/core/search.go index ae75738d644..80dfdda0db0 100644 --- a/commands/core/search.go +++ b/commands/core/search.go @@ -28,6 +28,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// PlatformSearch FIXMEDOC func PlatformSearch(ctx context.Context, req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error) { pm := commands.GetPackageManager(req) if pm == nil { diff --git a/commands/core/uninstall.go b/commands/core/uninstall.go index 031b5eb200c..2b8b75a62fe 100644 --- a/commands/core/uninstall.go +++ b/commands/core/uninstall.go @@ -28,6 +28,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// PlatformUninstall FIXMEDOC func PlatformUninstall(ctx context.Context, req *rpc.PlatformUninstallReq, taskCB commands.TaskProgressCB) (*rpc.PlatformUninstallResp, error) { pm := commands.GetPackageManager(req) if pm == nil { diff --git a/commands/core/upgrade.go b/commands/core/upgrade.go index 6099ccfc59e..ad430831ace 100644 --- a/commands/core/upgrade.go +++ b/commands/core/upgrade.go @@ -28,6 +28,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// PlatformUpgrade FIXMEDOC func PlatformUpgrade(ctx context.Context, req *rpc.PlatformUpgradeReq, downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) (*rpc.PlatformUpgradeResp, error) { diff --git a/commands/instances.go b/commands/instances.go index e26852e1ac3..d3eb0cccffd 100644 --- a/commands/instances.go +++ b/commands/instances.go @@ -55,10 +55,12 @@ type CoreInstance struct { discoveries []*discovery.Discovery } +// InstanceContainer FIXMEDOC type InstanceContainer interface { GetInstance() *rpc.Instance } +// GetPackageManager FIXMEDOC func GetPackageManager(req InstanceContainer) *packagemanager.PackageManager { i, ok := instances[req.GetInstance().GetId()] if !ok { @@ -67,6 +69,7 @@ func GetPackageManager(req InstanceContainer) *packagemanager.PackageManager { return i.pm } +// GetLibraryManager FIXMEDOC func GetLibraryManager(req InstanceContainer) *librariesmanager.LibrariesManager { i, ok := instances[req.GetInstance().GetId()] if !ok { @@ -75,6 +78,7 @@ func GetLibraryManager(req InstanceContainer) *librariesmanager.LibrariesManager return i.lm } +// GetDiscoveries FIXMEDOC func GetDiscoveries(req InstanceContainer) []*discovery.Discovery { i, ok := instances[req.GetInstance().GetId()] if !ok { @@ -149,6 +153,7 @@ func (instance *CoreInstance) startDiscoveries() error { return nil } +// Init FIXMEDOC func Init(ctx context.Context, req *rpc.InitReq, downloadCB DownloadProgressCB, taskCB TaskProgressCB, downloaderHeaders http.Header) (*rpc.InitResp, error) { inConfig := req.GetConfiguration() if inConfig == nil { @@ -202,6 +207,7 @@ func Init(ctx context.Context, req *rpc.InitReq, downloadCB DownloadProgressCB, }, nil } +// Destroy FIXMEDOC func Destroy(ctx context.Context, req *rpc.DestroyReq) (*rpc.DestroyResp, error) { id := req.GetInstance().GetId() if _, ok := instances[id]; !ok { @@ -237,6 +243,7 @@ func UpdateLibrariesIndex(ctx context.Context, req *rpc.UpdateLibrariesIndexReq, return nil } +// UpdateIndex FIXMEDOC func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB DownloadProgressCB) (*rpc.UpdateIndexResp, error) { id := req.GetInstance().GetId() coreInstance, ok := instances[id] @@ -286,6 +293,7 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexReq, downloadCB Downlo return &rpc.UpdateIndexResp{}, nil } +// Rescan FIXMEDOC func Rescan(ctx context.Context, req *rpc.RescanReq) (*rpc.RescanResp, error) { id := req.GetInstance().GetId() coreInstance, ok := instances[id] @@ -371,6 +379,7 @@ func createInstance(ctx context.Context, config *configs.Configuration, getLibOn return pm, lm, platformIndexErrors, librariesIndexError, nil } +// Download FIXMEDOC func Download(d *downloader.Downloader, label string, downloadCB DownloadProgressCB) error { if d == nil { // This signal means that the file is already downloaded diff --git a/commands/lib/download.go b/commands/lib/download.go index a46bddd4c85..fbc24a4cc53 100644 --- a/commands/lib/download.go +++ b/commands/lib/download.go @@ -29,6 +29,7 @@ import ( "github.com/sirupsen/logrus" ) +// LibraryDownload FIXMEDOC func LibraryDownload(ctx context.Context, req *rpc.LibraryDownloadReq, downloadCB commands.DownloadProgressCB, downloaderHeaders http.Header) (*rpc.LibraryDownloadResp, error) { logrus.Info("Executing `arduino lib download`") diff --git a/commands/lib/install.go b/commands/lib/install.go index dac7d74f3eb..a9212b6b963 100644 --- a/commands/lib/install.go +++ b/commands/lib/install.go @@ -29,6 +29,7 @@ import ( "github.com/sirupsen/logrus" ) +// LibraryInstall FIXMEDOC func LibraryInstall(ctx context.Context, req *rpc.LibraryInstallReq, downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { diff --git a/commands/lib/list.go b/commands/lib/list.go index b948a8d5677..b0c726b6ff3 100644 --- a/commands/lib/list.go +++ b/commands/lib/list.go @@ -32,6 +32,7 @@ type installedLib struct { Available *librariesindex.Release } +// LibraryList FIXMEDOC func LibraryList(ctx context.Context, req *rpc.LibraryListReq) (*rpc.LibraryListResp, error) { lm := commands.GetLibraryManager(req) @@ -79,6 +80,7 @@ func listLibraries(lm *librariesmanager.LibrariesManager, updatable bool, all bo return res } +// GetOutputLibrary FIXMEDOC func GetOutputLibrary(lib *libraries.Library) *rpc.Library { insdir := "" if lib.InstallDir != nil { @@ -123,6 +125,7 @@ func GetOutputLibrary(lib *libraries.Library) *rpc.Library { } } +// GetOutputRelease FIXMEDOC func GetOutputRelease(lib *librariesindex.Release) *rpc.LibraryRelease { // if lib != nil { return &rpc.LibraryRelease{ diff --git a/commands/lib/search.go b/commands/lib/search.go index eb7b1ba9abc..342ca6052e7 100644 --- a/commands/lib/search.go +++ b/commands/lib/search.go @@ -27,6 +27,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// LibrarySearch FIXMEDOC func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.LibrarySearchResp, error) { lm := commands.GetLibraryManager(req) if lm == nil { @@ -55,6 +56,7 @@ func LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.Library return &rpc.LibrarySearchResp{Libraries: res}, nil } +// GetLibraryParameters FIXMEDOC func GetLibraryParameters(rel *librariesindex.Release) *rpc.LibraryRelease { return &rpc.LibraryRelease{ Author: rel.Author, diff --git a/commands/lib/uninstall.go b/commands/lib/uninstall.go index ce864f8e535..3c23c64b200 100644 --- a/commands/lib/uninstall.go +++ b/commands/lib/uninstall.go @@ -25,6 +25,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// LibraryUninstall FIXMEDOC func LibraryUninstall(ctx context.Context, req *rpc.LibraryUninstallReq, taskCB commands.TaskProgressCB) error { lm := commands.GetLibraryManager(req) diff --git a/commands/lib/upgrade.go b/commands/lib/upgrade.go index ae0e4be1cd5..4150fb8433e 100644 --- a/commands/lib/upgrade.go +++ b/commands/lib/upgrade.go @@ -26,6 +26,7 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// LibraryUpgradeAll FIXMEDOC func LibraryUpgradeAll(ctx context.Context, req *rpc.LibraryUpgradeAllReq, downloadCB commands.DownloadProgressCB, taskCB commands.TaskProgressCB, downloaderHeaders http.Header) error { lm := commands.GetLibraryManager(req) diff --git a/commands/upload/upload.go b/commands/upload/upload.go index 1fb64da8bdc..c167ef4efd2 100644 --- a/commands/upload/upload.go +++ b/commands/upload/upload.go @@ -38,6 +38,7 @@ import ( serial "go.bug.st/serial.v1" ) +// Upload FIXMEDOC func Upload(ctx context.Context, req *rpc.UploadReq, outStream io.Writer, errStream io.Writer) (*rpc.UploadResp, error) { logrus.Info("Executing `arduino upload`") diff --git a/configs/navigate.go b/configs/navigate.go index 53f9690a549..9a4d5f5b17d 100644 --- a/configs/navigate.go +++ b/configs/navigate.go @@ -22,6 +22,7 @@ import ( "github.com/sirupsen/logrus" ) +// Navigate FIXMEDOC func (c *Configuration) Navigate(pwd *paths.Path) { parents := pwd.Clean().Parents() diff --git a/daemon/daemon.go b/daemon/daemon.go index db9e8efdac0..12a1e0ee45d 100644 --- a/daemon/daemon.go +++ b/daemon/daemon.go @@ -35,22 +35,27 @@ import ( "github.com/arduino/arduino-cli/rpc" ) +// ArduinoCoreServerImpl FIXMEDOC type ArduinoCoreServerImpl struct { DownloaderHeaders http.Header } +// BoardDetails FIXMEDOC func (s *ArduinoCoreServerImpl) BoardDetails(ctx context.Context, req *rpc.BoardDetailsReq) (*rpc.BoardDetailsResp, error) { return board.Details(ctx, req) } +// BoardList FIXMEDOC func (s *ArduinoCoreServerImpl) BoardList(ctx context.Context, req *rpc.BoardListReq) (*rpc.BoardListResp, error) { return board.List(ctx, req) } +// BoardListAll FIXMEDOC func (s *ArduinoCoreServerImpl) BoardListAll(ctx context.Context, req *rpc.BoardListAllReq) (*rpc.BoardListAllResp, error) { return board.ListAll(ctx, req) } +// BoardAttach FIXMEDOC func (s *ArduinoCoreServerImpl) BoardAttach(req *rpc.BoardAttachReq, stream rpc.ArduinoCore_BoardAttachServer) error { resp, err := board.Attach(stream.Context(), req, @@ -62,14 +67,17 @@ func (s *ArduinoCoreServerImpl) BoardAttach(req *rpc.BoardAttachReq, stream rpc. return stream.Send(resp) } +// Destroy FIXMEDOC func (s *ArduinoCoreServerImpl) Destroy(ctx context.Context, req *rpc.DestroyReq) (*rpc.DestroyResp, error) { return commands.Destroy(ctx, req) } +// Rescan FIXMEDOC func (s *ArduinoCoreServerImpl) Rescan(ctx context.Context, req *rpc.RescanReq) (*rpc.RescanResp, error) { return commands.Rescan(ctx, req) } +// UpdateIndex FIXMEDOC func (s *ArduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexReq, stream rpc.ArduinoCore_UpdateIndexServer) error { resp, err := commands.UpdateIndex(stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.UpdateIndexResp{DownloadProgress: p}) }, @@ -80,6 +88,7 @@ func (s *ArduinoCoreServerImpl) UpdateIndex(req *rpc.UpdateIndexReq, stream rpc. return stream.Send(resp) } +// UpdateLibrariesIndex FIXMEDOC func (s *ArduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesIndexReq, stream rpc.ArduinoCore_UpdateLibrariesIndexServer) error { err := commands.UpdateLibrariesIndex(stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.UpdateLibrariesIndexResp{DownloadProgress: p}) }, @@ -90,6 +99,7 @@ func (s *ArduinoCoreServerImpl) UpdateLibrariesIndex(req *rpc.UpdateLibrariesInd return stream.Send(&rpc.UpdateLibrariesIndexResp{}) } +// Init FIXMEDOC func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_InitServer) error { resp, err := commands.Init(stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.InitResp{DownloadProgress: p}) }, @@ -103,10 +113,12 @@ func (s *ArduinoCoreServerImpl) Init(req *rpc.InitReq, stream rpc.ArduinoCore_In return stream.Send(resp) } +// Version FIXMEDOC func (s *ArduinoCoreServerImpl) Version(ctx context.Context, req *rpc.VersionReq) (*rpc.VersionResp, error) { return &rpc.VersionResp{Version: cli.VersionInfo.VersionString}, nil } +// Compile FIXMEDOC func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoCore_CompileServer) error { resp, err := compile.Compile( stream.Context(), req, @@ -119,6 +131,7 @@ func (s *ArduinoCoreServerImpl) Compile(req *rpc.CompileReq, stream rpc.ArduinoC return stream.Send(resp) } +// PlatformInstall FIXMEDOC func (s *ArduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallReq, stream rpc.ArduinoCore_PlatformInstallServer) error { resp, err := core.PlatformInstall( stream.Context(), req, @@ -132,6 +145,7 @@ func (s *ArduinoCoreServerImpl) PlatformInstall(req *rpc.PlatformInstallReq, str return stream.Send(resp) } +// PlatformDownload FIXMEDOC func (s *ArduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReq, stream rpc.ArduinoCore_PlatformDownloadServer) error { resp, err := core.PlatformDownload( stream.Context(), req, @@ -144,6 +158,7 @@ func (s *ArduinoCoreServerImpl) PlatformDownload(req *rpc.PlatformDownloadReq, s return stream.Send(resp) } +// PlatformUninstall FIXMEDOC func (s *ArduinoCoreServerImpl) PlatformUninstall(req *rpc.PlatformUninstallReq, stream rpc.ArduinoCore_PlatformUninstallServer) error { resp, err := core.PlatformUninstall( stream.Context(), req, @@ -155,6 +170,7 @@ func (s *ArduinoCoreServerImpl) PlatformUninstall(req *rpc.PlatformUninstallReq, return stream.Send(resp) } +// PlatformUpgrade FIXMEDOC func (s *ArduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeReq, stream rpc.ArduinoCore_PlatformUpgradeServer) error { resp, err := core.PlatformUpgrade( stream.Context(), req, @@ -168,14 +184,17 @@ func (s *ArduinoCoreServerImpl) PlatformUpgrade(req *rpc.PlatformUpgradeReq, str return stream.Send(resp) } +// PlatformSearch FIXMEDOC func (s *ArduinoCoreServerImpl) PlatformSearch(ctx context.Context, req *rpc.PlatformSearchReq) (*rpc.PlatformSearchResp, error) { return core.PlatformSearch(ctx, req) } +// PlatformList FIXMEDOC func (s *ArduinoCoreServerImpl) PlatformList(ctx context.Context, req *rpc.PlatformListReq) (*rpc.PlatformListResp, error) { return core.PlatformList(ctx, req) } +// Upload FIXMEDOC func (s *ArduinoCoreServerImpl) Upload(req *rpc.UploadReq, stream rpc.ArduinoCore_UploadServer) error { resp, err := upload.Upload( stream.Context(), req, @@ -203,6 +222,7 @@ func feedStream(streamer func(data []byte)) io.Writer { return w } +// LibraryDownload FIXMEDOC func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadReq, stream rpc.ArduinoCore_LibraryDownloadServer) error { resp, err := lib.LibraryDownload( stream.Context(), req, @@ -215,6 +235,7 @@ func (s *ArduinoCoreServerImpl) LibraryDownload(req *rpc.LibraryDownloadReq, str return stream.Send(resp) } +// LibraryInstall FIXMEDOC func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallReq, stream rpc.ArduinoCore_LibraryInstallServer) error { err := lib.LibraryInstall( stream.Context(), req, @@ -228,6 +249,7 @@ func (s *ArduinoCoreServerImpl) LibraryInstall(req *rpc.LibraryInstallReq, strea return stream.Send(&rpc.LibraryInstallResp{}) } +// LibraryUninstall FIXMEDOC func (s *ArduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallReq, stream rpc.ArduinoCore_LibraryUninstallServer) error { err := lib.LibraryUninstall(stream.Context(), req, func(p *rpc.TaskProgress) { stream.Send(&rpc.LibraryUninstallResp{TaskProgress: p}) }, @@ -238,6 +260,7 @@ func (s *ArduinoCoreServerImpl) LibraryUninstall(req *rpc.LibraryUninstallReq, s return stream.Send(&rpc.LibraryUninstallResp{}) } +// LibraryUpgradeAll FIXMEDOC func (s *ArduinoCoreServerImpl) LibraryUpgradeAll(req *rpc.LibraryUpgradeAllReq, stream rpc.ArduinoCore_LibraryUpgradeAllServer) error { err := lib.LibraryUpgradeAll(stream.Context(), req, func(p *rpc.DownloadProgress) { stream.Send(&rpc.LibraryUpgradeAllResp{Progress: p}) }, @@ -250,10 +273,12 @@ func (s *ArduinoCoreServerImpl) LibraryUpgradeAll(req *rpc.LibraryUpgradeAllReq, return stream.Send(&rpc.LibraryUpgradeAllResp{}) } +// LibrarySearch FIXMEDOC func (s *ArduinoCoreServerImpl) LibrarySearch(ctx context.Context, req *rpc.LibrarySearchReq) (*rpc.LibrarySearchResp, error) { return lib.LibrarySearch(ctx, req) } +// LibraryList FIXMEDOC func (s *ArduinoCoreServerImpl) LibraryList(ctx context.Context, req *rpc.LibraryListReq) (*rpc.LibraryListResp, error) { return lib.LibraryList(ctx, req) } diff --git a/output/table.go b/output/table.go index 7757e72334a..5273576126d 100644 --- a/output/table.go +++ b/output/table.go @@ -22,6 +22,7 @@ import ( "math" ) +// Table FIXMEDOC type Table struct { hasHeader bool columnsCount int @@ -29,23 +30,29 @@ type Table struct { rows []*TableRow } +// TableRow FIXMEDOC type TableRow struct { cells []TextBox } +// NewTable FIXMEDOC func NewTable() *Table { return &Table{ rows: []*TableRow{}, } } +// TableColumnWidthMode FIXMEDOC type TableColumnWidthMode int const ( + // Minimum FIXMEDOC Minimum TableColumnWidthMode = iota + // Average FIXMEDOC Average ) +// SetColumnWidthMode FIXMEDOC func (t *Table) SetColumnWidthMode(x int, mode TableColumnWidthMode) { for len(t.columnsWidthMode) <= x { t.columnsWidthMode = append(t.columnsWidthMode, Minimum) @@ -74,6 +81,7 @@ func (t *Table) makeTableRow(columns ...interface{}) *TableRow { return &TableRow{cells: cells} } +// SetHeader FIXMEDOC func (t *Table) SetHeader(columns ...interface{}) { row := t.makeTableRow(columns...) if t.hasHeader { @@ -84,11 +92,13 @@ func (t *Table) SetHeader(columns ...interface{}) { } } +// AddRow FIXMEDOC func (t *Table) AddRow(columns ...interface{}) { row := t.makeTableRow(columns...) t.rows = append(t.rows, row) } +// Render FIXMEDOC func (t *Table) Render() string { // find max width for each row average := make([]int, t.columnsCount) diff --git a/output/text.go b/output/text.go index f19753f25e3..e8151dfd701 100644 --- a/output/text.go +++ b/output/text.go @@ -31,41 +31,50 @@ var yellow = color.New(color.FgYellow).SprintfFunc() var white = color.New(color.FgWhite).SprintfFunc() var hiWhite = color.New(color.FgHiWhite).SprintfFunc() +// Red FIXMEDOC func Red(in string) *Text { return &Text{raw: red(in), clean: in} } +// Blue FIXMEDOC func Blue(in string) *Text { return &Text{raw: blue(in), clean: in} } +// Green FIXMEDOC func Green(in string) *Text { return &Text{raw: green(in), clean: in} } +// Yellow FIXMEDOC func Yellow(in string) *Text { return &Text{raw: yellow(in), clean: in} } +// White FIXMEDOC func White(in string) *Text { return &Text{raw: white(in), clean: in} } +// HiWhite FIXMEDOC func HiWhite(in string) *Text { return &Text{raw: hiWhite(in), clean: in} } +// TextBox FIXMEDOC type TextBox interface { Len() int Pad(availableWidth int) string } +// Text FIXMEDOC type Text struct { clean string raw string justify int } +// Len FIXMEDOC func (t *Text) Len() int { return utf8.RuneCountInString(t.clean) } @@ -74,18 +83,22 @@ func (t *Text) Len() int { // return t.raw // } +// JustifyLeft FIXMEDOC func (t *Text) JustifyLeft() { t.justify = 0 } +// JustifyCenter FIXMEDOC func (t *Text) JustifyCenter() { t.justify = 1 } +// JustifyRight FIXMEDOC func (t *Text) JustifyRight() { t.justify = 2 } +// Pad FIXMEDOC func (t *Text) Pad(totalLen int) string { delta := totalLen - t.Len() switch t.justify { @@ -108,6 +121,7 @@ func spaces(n int) string { return res } +// Sprintf FIXMEDOC func Sprintf(format string, args ...interface{}) TextBox { cleanArgs := make([]interface{}, len(args)) for i, arg := range args { diff --git a/version/version.go b/version/version.go index c59cc26c398..b8326b82bd3 100644 --- a/version/version.go +++ b/version/version.go @@ -29,6 +29,7 @@ var ( buildDate = time.Time{} ) +// Info FIXMEDOC type Info struct { Application string `json:"Application"` VersionString string `json:"VersionString"` @@ -36,6 +37,7 @@ type Info struct { BuildDate time.Time `json:"BuildDate"` } +// NewInfo FIXMEDOC func NewInfo(application string) *Info { return &Info{ Application: application,