Skip to content

Commit

Permalink
Small refactoring and a bit of documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
markelog committed Dec 24, 2017
1 parent 4daf4fb commit 5ab4eb3
Show file tree
Hide file tree
Showing 20 changed files with 294 additions and 260 deletions.
4 changes: 2 additions & 2 deletions cmd/commands/path/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import (

"github.com/spf13/cobra"

"github.com/markelog/eclectica/initiate"
"github.com/markelog/eclectica/plugins"
"github.com/markelog/eclectica/shell"
)

// Command config
Expand All @@ -23,7 +23,7 @@ var Command = &cobra.Command{
// Updates the path environment variable
func run(c *cobra.Command, args []string) {
path := os.Getenv("PATH")
addition := initiate.Compose(plugins.Plugins)
addition := shell.Compose(plugins.Plugins)

if strings.Contains(path, addition) {
fmt.Print(path)
Expand Down
19 changes: 0 additions & 19 deletions cmd/info/info.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (

"github.com/markelog/eclectica/cmd/print"
"github.com/markelog/eclectica/plugins"
"github.com/markelog/eclectica/variables"
"github.com/markelog/eclectica/versions"

"github.com/markelog/eclectica/cmd/print/spinner"
Expand Down Expand Up @@ -97,19 +96,6 @@ func GetLanguage(args []string) (language, version string) {
return "", ""
}

// Get command from args list
func GetCommand(args []string) string {
for _, element := range args {
for _, command := range variables.NonInstallCommands {
if command == element {
return command
}
}
}

return ""
}

func GetSpinner(language string, prefix spinner.SpinnerFn) *spinner.Spinner {
c, _ := curse.New()

Expand Down Expand Up @@ -178,8 +164,3 @@ func HasVersion(args []string) bool {

return version != ""
}

// Is this is non-install command in args list?
func NonInstallCommand(args []string) bool {
return GetCommand(args) != ""
}
20 changes: 0 additions & 20 deletions cmd/info/info_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,4 @@ var _ = Describe("info", func() {
Expect(language).To(Equal(""))
})
})

Describe("NonInstallCommand", func() {
It("should detect command", func() {
hasCommand := info.NonInstallCommand([]string{"-r", "ls"})

Expect(hasCommand).To(Equal(true))
})

It("should detect command in different sequence", func() {
hasCommand := info.NonInstallCommand([]string{"ls", "-r"})

Expect(hasCommand).To(Equal(true))
})

It("should not detect command", func() {
hasCommand := info.NonInstallCommand([]string{"-r", "[email protected]"})

Expect(hasCommand).To(Equal(false))
})
})
})
57 changes: 3 additions & 54 deletions console/console.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
// Package console provides helpful console related methods
package console

import (
"io"
"io/ioutil"
"os"
"os/exec"
"reflect"
"regexp"
"strings"

"github.com/go-errors/errors"
"golang.org/x/crypto/ssh/terminal"

"github.com/markelog/eclectica/cmd/print"
"github.com/markelog/eclectica/variables"
)

// Get gets cmd instance by passing array to exec.Command
Expand All @@ -30,35 +25,8 @@ func Get(args []string) *exec.Cmd {
return cmd
}

// Start Shell
func Shell() {

// If shell is not output - get out
if terminal.IsTerminal(int(os.Stdout.Fd())) == false {
return
}

var procAttr os.ProcAttr

procAttr.Files = []*os.File{
os.Stdin,
os.Stdout,
os.Stderr,
}

args := []string{
variables.GetShellName(),
}

proc, err := os.StartProcess(variables.GetShellPath(), args, &procAttr)
print.Error(err)

_, err = proc.Wait()
print.Error(err)
}

// GetError is just facade to handling console errors of the pipes
func GetError(err error, stdout, stderr io.ReadCloser) error {
// Error is just facade for handling console pipes errors
func Error(err error, stdout, stderr io.ReadCloser) error {
if stdout == nil || stderr == nil {
return nil
}
Expand Down Expand Up @@ -90,22 +58,3 @@ func GetError(err error, stdout, stderr io.ReadCloser) error {

return err
}

func trimMessage(message string) (result string) {
result = strings.TrimSpace(message)

messageLength := 30

messages := strings.Split(result, "\n")
last := len(messages) - 1

result = messages[last]

if len(result) < messageLength {
return
}

result = "..." + result[messageLength-3:]

return
}
9 changes: 9 additions & 0 deletions docs/00-introduction.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
---
title: Introduction
---

Up deploys infinitely scalable serverless apps, APIs, and static websites in seconds, so you can get back to working on what makes your product unique.

Up focuses on deploying "vanilla" HTTP servers so there's nothing new to learn, just develop with your favorite existing frameworks such as Express, Koa, Django, Golang net/http or others.

Up currently supports Node.js, Golang, Python, Java, Crystal, and static sites out of the box. Up is platform-agnostic, supporting AWS Lambda and API Gateway as the first targets. You can think of Up as self-hosted Heroku style user experience for a fraction of the price, with the security, flexibility, and scalability of AWS.
84 changes: 0 additions & 84 deletions initiate/initiate.go

This file was deleted.

32 changes: 26 additions & 6 deletions io/io.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// Package io provides some helpful IO functions with simplified
// signatures in the context of eclectica package
package io

import (
Expand All @@ -9,8 +11,14 @@ import (
"github.com/go-errors/errors"
)

const (
perm = 0700
)

// Walker signature function
type Walker func(path string) bool

// walkUp walker up to filesystem tree
func walkUp(path string, fn Walker) {
current := path

Expand All @@ -21,21 +29,25 @@ func walkUp(path string, fn Walker) {

for {
if current == "" || current == "/" {
return
break
}

current = filepath.Dir(current)

stop = fn(current)
if stop == true {
return
break
}
}

return
}

// GetVersion finds a file by provided argument and extracts
// the version defined in it
func GetVersion(args ...interface{}) (version, path string, err error) {
current := "current"

if len(args) > 1 {
path, err = FindDotFile(args[0], args[1])
} else {
Expand All @@ -47,7 +59,7 @@ func GetVersion(args ...interface{}) (version, path string, err error) {
}

if _, err := os.Stat(path); os.IsNotExist(err) {
return "current", "", nil
return current, "", nil
}

file, err := os.Open(path)
Expand All @@ -67,9 +79,11 @@ func GetVersion(args ...interface{}) (version, path string, err error) {
return "", "", scannerErr
}

return "current", "", nil
return current, "", nil
}

// FindDotFile finds file up in the filesystem tree
// by provided list of possible files
func FindDotFile(args ...interface{}) (versionPath string, err error) {
var path string
dots := args[0].([]string)
Expand Down Expand Up @@ -101,8 +115,9 @@ func FindDotFile(args ...interface{}) (versionPath string, err error) {
return
}

// CreateDir creates dir with predefined perms
func CreateDir(path string) (string, error) {
err := os.MkdirAll(path, 0700)
err := os.MkdirAll(path, perm)

if err != nil {
return "", errors.New(err)
Expand All @@ -111,17 +126,19 @@ func CreateDir(path string) (string, error) {
return path, nil
}

// WriteFile writes file with default perms and accepts a string as data
func WriteFile(path, content string) error {
data := []byte(content)

err := ioutil.WriteFile(path, data, 0700)
err := ioutil.WriteFile(path, data, perm)
if err != nil {
return errors.New(err)
}

return nil
}

// Read file and return a content string
func Read(path string) string {
bytes, err := ioutil.ReadFile(path)

Expand All @@ -132,6 +149,7 @@ func Read(path string) string {
return string(bytes)
}

// ListVersions lists installed versions for the given path
func ListVersions(path string) (vers []string) {
vers = []string{}

Expand All @@ -150,6 +168,8 @@ func ListVersions(path string) (vers []string) {
return
}

// Symlink removes the link if file already
// present and the creates another symlink
func Symlink(current, base string) (err error) {
// Remove symlink just in case it's already present
err = os.RemoveAll(current)
Expand Down
Loading

0 comments on commit 5ab4eb3

Please sign in to comment.