Unverified Commit fe4814b0 authored by red_car's avatar red_car Committed by GitHub

Lint tasks refactory (#250)

* replace golangci-lint with govet and golint go-task task

going in the direction of removing travis.ci in favour of drone io,
and in order to have a clean linting check output, golangci-lint was
removed because the output for this codebase was too confusing

* refactor task check and add task check-legacy

in order to be aligned with test task style we will have a legacy
(ugly) lint output if requested and meanwhile  we will focus on the
"new refactored part" of the code with lint and fmt to speed up
the development and refactoring

* removed go lint check for legacy lint task

no need to be obsessed on linting for a module that will be properly
refactored out from the legacy

* add dynamic DEFAULT_TARGET generation list

* replace golangci-lint with simple go-task check

* fix upload for integ and unit test in codeconv.io

* raise to 10m test timeput for unit and integ tests

* add task test-unit-race to specificly run unit test with rece condition
detection

in order to do not slow down testing too much also because we do not
have particular race conditions to detect at the moment

* clean from drone configuration and related dockerfiles

* add missing documentation temporary comment to make linter happy

this is a FIXME commit, in next months all the FIXMEDOCS placeholders
must be replaced with proper documentation
parent bb7a5db3
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
......@@ -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'
......@@ -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
......@@ -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
......@@ -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)
......
......@@ -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 {
......
......@@ -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,
......
......@@ -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()
......
......@@ -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)
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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)
......
......@@ -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) {
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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 {
......
......@@ -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) {
......
......@@ -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
......
......@@ -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`")
......
......@@ -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 {
......
......@@ -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{
......
......@@ -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,
......
......@@ -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)
......
......@@ -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)
......
......@@ -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`")
......
......@@ -22,6 +22,7 @@ import (
"github.com/sirupsen/logrus"
)
// Navigate FIXMEDOC
func (c *Configuration) Navigate(pwd *paths.Path) {
parents := pwd.Clean().Parents()
......
......@@ -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)
}
......@@ -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)
......
......@@ -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 {
......
......@@ -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,
......
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