Skip to content

Commit

Permalink
Lint, docs and add more badges as well
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog committed Dec 25, 2017
1 parent 6102a9b commit b5b4f28
Show file tree
Hide file tree
Showing 41 changed files with 357 additions and 159 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test: install
int: install
$(eval tmp := $(TMPDIR)"eclectica")

@echo "[+] intergration testing"
@echo "[+] integration testing"

@rm -rf $(tmp)
@mkdir -p $(tmp)
Expand All @@ -34,7 +34,7 @@ int: install
int-ci:
$(eval tmp := $(TMPDIR)"eclectica")

@echo "[+] intergration testing"
@echo "[+] integration testing"

@rm -rf $(tmp)
@mkdir -p $(tmp)
Expand Down
4 changes: 2 additions & 2 deletions bin/ec/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ var (
bins = variables.DefaultInstall
)

func shouldRun(langauge string) bool {
func shouldRun(language string) bool {
if os.Getenv("TEST_ALL") == "true" {
return true
}

if os.Getenv("TEST_LANGUAGE") == langauge {
if os.Getenv("TEST_LANGUAGE") == language {
return true
}

Expand Down
8 changes: 4 additions & 4 deletions cmd/commands/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var isRemote bool
var isLocal bool

// Reinstall global modules from previous version?
var WithModules bool
var withModules bool

var use = "ec [<language>@<version>]"

Expand All @@ -25,12 +25,11 @@ var Command = &cobra.Command{
Hidden: true,
}

// Add command to root command
// Register command to root command
func Register(cmd *cobra.Command) {
Command.AddCommand(cmd)
}

// Init
func init() {
Command.SetHelpTemplate(help)
Command.SetUsageTemplate(usage)
Expand All @@ -40,14 +39,15 @@ func init() {
flags := Command.PersistentFlags()
flags.BoolVarP(&isRemote, "remote", "r", false, "Get remote versions")
flags.BoolVarP(&isLocal, "local", "l", false, "Install as local version i.e. language will be installed only to local folder")
flags.BoolVarP(&WithModules, "with-modules", "w", false, "Reinstall global modules from the previous version (currently works only for node.js)")
flags.BoolVarP(&withModules, "with-modules", "w", false, "Reinstall global modules from the previous version (currently works only for node.js)")
}

func augment() {
// Insert command "install" in args
os.Args = append(os.Args[:1], append([]string{"install"}, os.Args[1:]...)...)
}

// Execute the command
func Execute() {

args := os.Args[1:]
Expand Down
1 change: 1 addition & 0 deletions cmd/commands/install/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"github.com/markelog/eclectica/plugins"
)

// SetupEvents sets events
func SetupEvents(plugin *plugins.Plugin) {
var spinner *CustomSpinner.Spin

Expand Down
21 changes: 8 additions & 13 deletions cmd/commands/install/install.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package install installs the langauges
// Package install installs the languages
package install

import (
Expand Down Expand Up @@ -138,14 +138,14 @@ func run(cmd *cobra.Command, args []string) {
install(language, version)
return

// In case of `ec -r <language>` or `ec <language> -r`
} else {
language, version, err = info.AskRemote()
print.Error(err)

install(language, version)
return
}

// In case of `ec -r <language>` or `ec <language> -r`
language, version, err = info.AskRemote()
print.Error(err)

install(language, version)
return
}

// In case of `ec <language>`
Expand All @@ -163,11 +163,6 @@ func run(cmd *cobra.Command, args []string) {
os.Exit(1)
}

// Add command to root command
func Register(cmd *cobra.Command) {
Command.AddCommand(cmd)
}

// Init
func init() {
flags := Command.PersistentFlags()
Expand Down
20 changes: 12 additions & 8 deletions cmd/info/info.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package info provides ways to acquiring additional info from the user
package info

import (
Expand Down Expand Up @@ -26,7 +27,7 @@ func Ask() (language, version string, err error) {
return
}

// Ask for version
// AskVersion asks version from the user
func AskVersion(language string) (version string, err error) {
vers := plugins.New(&plugins.Args{
Language: language,
Expand All @@ -42,15 +43,15 @@ func AskVersion(language string) (version string, err error) {
return
}

// Ask for language and remote version
// AskRemote asks for remote version from the user
func AskRemote() (language, version string, err error) {
language = list.GetWith("Language", plugins.Plugins)
version, err = AskRemoteVersion(language)

return
}

// Ask for list of remote versions
// AskRemoteVersions asks for list of remote versions
func AskRemoteVersions(language string) (vers []string, err error) {
remoteList, err := ListRemote(language)
if err != nil {
Expand All @@ -63,7 +64,7 @@ func AskRemoteVersions(language string) (vers []string, err error) {
return
}

// Ask for list of remote version
// AskRemoteVersion asks for list of remote version
func AskRemoteVersion(language string) (version string, err error) {
versions, err := AskRemoteVersions(language)

Expand All @@ -76,7 +77,7 @@ func AskRemoteVersion(language string) (version string, err error) {
return
}

// Get supported language from args list
// GetLanguage gets supported language from args list
func GetLanguage(args []string) (language, version string) {
for _, element := range args {
data := strings.Split(element, "@")
Expand All @@ -96,7 +97,8 @@ func GetLanguage(args []string) (language, version string) {
return "", ""
}

func GetSpinner(language string, prefix spinner.SpinnerFn) *spinner.Spinner {
// GetSpinner gets the spinner, just easier that way
func GetSpinner(language string, prefix spinner.Fn) *spinner.Spinner {
c, _ := curse.New()

before := func() {}
Expand All @@ -115,6 +117,7 @@ func GetSpinner(language string, prefix spinner.SpinnerFn) *spinner.Spinner {
return spinner.New(before, after, prefix, postfix)
}

// ListRemote lists remote version from the plugin indirectly
func ListRemote(language string) (versions map[string][]string, err error) {
plugin := plugins.New(&plugins.Args{
Language: language,
Expand All @@ -133,6 +136,7 @@ func ListRemote(language string) (versions map[string][]string, err error) {
return
}

// FullListRemote lists remote version from the plugin directly
func FullListRemote(language string) (versions []string, err error) {
plugin := plugins.New(&plugins.Args{
Language: language,
Expand All @@ -151,14 +155,14 @@ func FullListRemote(language string) (versions []string, err error) {
return
}

// Is there an langauge in args list?
// HasLanguage do we have language in args list?
func HasLanguage(args []string) bool {
language, _ := GetLanguage(args)

return language != ""
}

// Is there an version in args list?
// HasVersion do we have version in args list?
func HasVersion(args []string) bool {
_, version := GetLanguage(args)

Expand Down
22 changes: 15 additions & 7 deletions cmd/print/custom-spinner/custom-spinner.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
// Package CustomSpinner provides spinner with additional custom logic
package CustomSpinner

import (
"fmt"
"sync"
"time"

"github.com/markelog/curse"

"github.com/markelog/eclectica/cmd/print"
"github.com/markelog/eclectica/cmd/print/spinner"

"github.com/markelog/curse"
)

var (
Expand All @@ -18,16 +19,20 @@ var (
timeout = print.Timeout
)

type SpinArgs struct {
Header, Item, Note, Message string
}

// Spin essential struct
type Spin struct {
SpinArgs
Spinner *spinner.Spinner
mutex *sync.Mutex

mutex *sync.Mutex
}

// SpinArgs is arguments struct for New() method
type SpinArgs struct {
Header, Item, Note, Message string
}

// New returns custom spinner struct
func New(args *SpinArgs) *Spin {
me := &Spin{
mutex: &sync.Mutex{},
Expand All @@ -37,6 +42,7 @@ func New(args *SpinArgs) *Spin {
return me
}

// Set new data for the spinner
func (me *Spin) Set(args *SpinArgs) {
me.mutex.Lock()

Expand All @@ -63,10 +69,12 @@ func (me *Spin) Set(args *SpinArgs) {
}
}

// Start the spinner
func (me Spin) Start() {
me.Spinner.Start()
}

// Stop the spinner
func (me Spin) Stop() {
me.Spinner.Stop()
}
Expand Down
11 changes: 8 additions & 3 deletions cmd/print/print.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,14 @@ import (
)

var (
Gray = ansi.ColorCode("240")
White = ansi.ColorCode("white+b")
Reset = ansi.ColorCode("reset")

// Gray color
Gray = ansi.ColorCode("240")
// White color
White = ansi.ColorCode("white+b")
// Reset ASCII-sequence
Reset = ansi.ColorCode("reset")
// Timeout for anything general
Timeout = 200 * time.Millisecond
)

Expand Down
20 changes: 13 additions & 7 deletions cmd/print/spinner/spinner.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Package spinner provides essential (empty) spinner
package spinner

import (
Expand All @@ -9,18 +10,21 @@ import (
spin "github.com/tj/go-spin"
)

type SpinnerFn func()

// Spinner essential struct
type Spinner struct {
isDone bool
Before, After, Prefix, Postfix Fn

mutex *sync.Mutex
Spin *spin.Spinner
Spin *spin.Spinner

Before, After, Prefix, Postfix SpinnerFn
isDone bool
mutex *sync.Mutex
}

func New(before, after, prefix, postfix SpinnerFn) *Spinner {
// Fn callback signature
type Fn func()

// New returns new spinner struct
func New(before, after, prefix, postfix Fn) *Spinner {
return &Spinner{
isDone: false,

Expand All @@ -34,6 +38,7 @@ func New(before, after, prefix, postfix SpinnerFn) *Spinner {
}
}

// Start the spinner
func (spinner *Spinner) Start() {
spinner.mutex.Lock()
defer spinner.mutex.Unlock()
Expand Down Expand Up @@ -68,6 +73,7 @@ func (spinner *Spinner) Start() {
}()
}

// Stop the spinner
func (spinner *Spinner) Stop() {
spinner.mutex.Lock()
defer spinner.mutex.Unlock()
Expand Down
8 changes: 4 additions & 4 deletions pkg/pkg.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Package provides helpful base interfaces and struct definitions
// Package pkg provides helpful base interfaces and struct definitions
package pkg

import "github.com/chuckpreslar/emission"
Expand Down Expand Up @@ -61,17 +61,17 @@ func (base Base) Rollback() error {
return nil
}

// Environment get needed environment variables and values
// Environment returns list of the all needed envionment variables
func (base Base) Environment() (result []string, err error) {
return
}

// Info gets plugin related info
// Info provides all the info needed for installation of the plugin
func (base Base) Info() (result map[string]string) {
return
}

// ListRemote gets availiable remote version for this plugin
// ListRemote returns list of the all available remote versions
func (base Base) ListRemote() (result []string, err error) {
return
}
Loading

0 comments on commit b5b4f28

Please sign in to comment.