Skip to content

Commit

Permalink
Adding some core libraries, command not implemented yet, refactoring …
Browse files Browse the repository at this point in the history
…String() functions of Core, Release, Library, libraries.Release @mastrolinux
  • Loading branch information
saniales committed Jun 21, 2017
1 parent 27c8c8a commit c1de609
Show file tree
Hide file tree
Showing 7 changed files with 450 additions and 7 deletions.
12 changes: 7 additions & 5 deletions cmd/arduino.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,16 @@ import (
)

const (
bashAutoCompletionFunction = `
bashAutoCompletionFunction = `
__arduino_autocomplete()
{
case $(last_command) in
arduino_lib)
opts="install uninstall list search version"
;;
arduino_core)
opts="install uninstall list search version"
;;
arduino_lib_list)
opts="update"
;;
Expand All @@ -61,10 +64,9 @@ const (
return 0
fi
return 1
}`,

// ArduinoVersion represents Arduino CLI version number.
ArduinoVersion string = "0.0.1-pre-alpha"
}`
// ArduinoVersion represents Arduino CLI version number.
ArduinoVersion string = "0.0.1-pre-alpha"
)

// GlobalFlags represents flags available in all the program.
Expand Down
44 changes: 44 additions & 0 deletions cmd/arduino_core.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package cmd

import (
"github.com/spf13/cobra"
)

var arduinoCoreCmd = &cobra.Command{
Use: "core",
Short: "Arduino Core operations",
Long: `Arduino Core operations`,
}

func init() {
arduinoCmd.AddCommand(arduinoCoreCmd)
}
50 changes: 50 additions & 0 deletions cmd/arduino_core_list.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package cmd

import (
"github.com/spf13/cobra"
)

var arduinoCoreListCmd = &cobra.Command{
Use: "list",
Short: "Shows the list of installed cores",
Long: `Shows the list of installed cores.
With -v tag (up to 2 times) can provide more verbose output.`,
Run: executeCoreListCommand,
}

func init() {
arduinoCoreCmd.AddCommand(arduinoCoreListCmd)
}

func executeCoreListCommand(cmd *cobra.Command, args []string) {

}
4 changes: 2 additions & 2 deletions cmd/pretty_print.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,15 @@ func prettyPrintStatus(status *libraries.StatusContext) {

func prettyPrintDownloadFileIndex() error {
if GlobalFlags.Verbose > 0 {
fmt.Print("Downloading a new index file from download.arduino.cc ... ")
fmt.Print("Downloading from download.arduino.cc ... ")
}

err := libraries.DownloadLibrariesFile()
if err != nil {
if GlobalFlags.Verbose > 0 {
fmt.Println("ERROR")
}
fmt.Println("Cannot download index file, check your network connection.")
fmt.Println("Cannot download file, check your network connection.")
return err
}

Expand Down
115 changes: 115 additions & 0 deletions cores/cores.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/*
* This file is part of arduino-cli.
*
* arduino-cli is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* As a special exception, you may use this file as part of a free software
* library without restriction. Specifically, if other files instantiate
* templates or use macros or inline functions from this file, or you compile
* this file and link it with other files to produce an executable, this
* file does not by itself cause the resulting executable to be covered by
* the GNU General Public License. This exception does not however
* invalidate any other reasons why the executable file might be covered by
* the GNU General Public License.
*
* Copyright 2017 BCMI LABS SA (http://www.arduino.cc/)
*/

package cores

import (
"fmt"
"strings"

"github.com/pmylund/sortutil"
)

// Core represents a core package.
type Core struct {
Name string // The name of the Core Package.
Architecture string // The name of the architecture of this package.
Category string // The category which this core package belongs to.
Releases map[string]*Release // The Releases of this core package, labeled by version.
}

// Release represents a release of a core package.
type Release struct {
Version string
ArchiveFileName string
Checksum string
Size int64
Boards []string
}

// GetVersion returns the specified release corresponding the provided version,
// or nil if not found.
func (core *Core) GetVersion(version string) *Release {
return core.Releases[version]
}

// Versions returns all the version numbers in this Core Package.
func (core *Core) Versions() []string {
versions := make([]string, len(core.Releases))
i := 0
for version := range core.Releases {
versions[i] = version
i++
}
sortutil.CiAsc(versions)
return versions
}

// Latest obtains latest version of a core package.
func (core *Core) Latest() *Release {
return core.GetVersion(core.latestVersion())
}

// latestVersion obtains latest version number.
//
// It uses lexicographics to compare version strings.
func (core *Core) latestVersion() string {
versions := core.Versions()
if len(versions) > 0 {
return versions[0]
}
return ""
}

func (core *Core) String(verbosity int) (res string) {
if verbosity > 0 {
res += fmt.Sprintf("Name : %s\n", core.Name)
res += fmt.Sprintf("Architecture: %s\n", core.Architecture)
res += fmt.Sprintf("Category : %s\n", core.Category)
if verbosity > 1 {
res += "Releases:\n"
for _, release := range core.Releases {
res += fmt.Sprintf("%s\n", release.String())
}
} else {
res += fmt.Sprintf("Releases : %s", core.Versions())
}
} else {
res = fmt.Sprintf("%s\n", core.Name)
}
}

func (release *Release) String() string {
res := fmt.Sprintf("Version : %s\n", release.Version)
res += fmt.Sprintf("Boards : \n%s\n", strings.Join(release.Boards, ", "))
res += fmt.Sprintf("Archive File Name : %s\n", release.ArchiveFileName)
res += fmt.Sprintf("Checksum : %s\n", release.Checksum)
res += fmt.Sprintf("File Size : %d\n", release.Size)
return res
}
Loading

0 comments on commit c1de609

Please sign in to comment.