You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openserverless.apache.org by ms...@apache.org on 2024/08/01 11:10:31 UTC
(openserverless-cli) branch main updated (4290d6b -> 224feaa)
This is an automated email from the ASF dual-hosted git repository.
msciabarra pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/openserverless-cli.git
from 4290d6b extraction from archives
new d40dc91 extract test
new 224feaa almost all fixed
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
go.mod | 5 ++-
go.sum | 2 --
tests/auto_setup.bats | 10 +++---
tests/extract.bats | 2 +-
tests/plugin.bats | 6 ++--
tests/update.bats | 2 +-
tools/sh.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++
tools/tools.go | 20 ++++++++++-
version.txt | 2 +-
9 files changed, 126 insertions(+), 18 deletions(-)
create mode 100644 tools/sh.go
(openserverless-cli) 01/02: extract test
Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
msciabarra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openserverless-cli.git
commit d40dc91bca98d63199daa54fa1f6b698657beea1
Author: Michele Sciabarra <mi...@sciabarra.com>
AuthorDate: Thu Aug 1 11:16:39 2024 +0200
extract test
---
go.mod | 3 +--
go.sum | 2 --
tests/extract.bats | 2 +-
version.txt | 2 +-
4 files changed, 3 insertions(+), 6 deletions(-)
diff --git a/go.mod b/go.mod
index 856d5f3..14d9b33 100644
--- a/go.mod
+++ b/go.mod
@@ -22,6 +22,7 @@ require (
github.com/sciabarracom/openwhisk-cli v1.2.1
github.com/sciabarracom/task/v3 v3.38.9
github.com/stretchr/testify v1.9.0
+ github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
github.com/zalando/go-keyring v0.2.5
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
golang.org/x/term v0.22.0
@@ -92,9 +93,7 @@ require (
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/sjson v1.2.4 // indirect
- github.com/ulikunitz/xz v0.5.12 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
- github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
github.com/zeebo/xxh3 v1.0.2 // indirect
golang.org/x/crypto v0.25.0 // indirect
golang.org/x/mod v0.19.0 // indirect
diff --git a/go.sum b/go.sum
index 50a64be..72a88e3 100644
--- a/go.sum
+++ b/go.sum
@@ -394,8 +394,6 @@ github.com/tidwall/pretty v1.2.0/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhso
github.com/tidwall/sjson v1.2.4 h1:cuiLzLnaMeBhRmEv00Lpk3tkYrcxpmbU81tAY4Dw0tc=
github.com/tidwall/sjson v1.2.4/go.mod h1:098SZ494YoMWPmMO6ct4dcFnqxwj9r/gF0Etp19pSNM=
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5/go.mod h1:ncp9v5uamzpCO7NfCPTXjqaC+bZgJeR0sMTm6dMHP7U=
-github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
-github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM=
github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw=
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofmx9yWTog9BfvIu0q41lo=
diff --git a/tests/extract.bats b/tests/extract.bats
index 3b79a27..5b53e37 100644
--- a/tests/extract.bats
+++ b/tests/extract.bats
@@ -24,7 +24,7 @@ setup() {
@test "extract" {
run ops -extract
- assert_line("Usage: file.(zip|tgz|tar[.gz|.bz2|.xz]) target")
+ assert_line "Usage: file.(zip|tgz|tar[.gz|.bz2|.xz]) target"
curl -sL -o7zip.tar.xz https://www.7-zip.org/a/7z2407-linux-x64.tar.xz
run ops -extract 7zip.tar.xz missing
diff --git a/version.txt b/version.txt
index 8d7a4ad..9a30fd2 100644
--- a/version.txt
+++ b/version.txt
@@ -1 +1 @@
-0.1.0-2407311501.dev
+0.1.0-2408011116.dev
(openserverless-cli) 02/02: almost all fixed
Posted by ms...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
msciabarra pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/openserverless-cli.git
commit 224feaaa4c4ecd8435b33c0dceff8bb74bdc6778
Author: Michele Sciabarra <mi...@sciabarra.com>
AuthorDate: Thu Aug 1 13:10:23 2024 +0200
almost all fixed
---
go.mod | 2 +-
tests/auto_setup.bats | 10 +++---
tests/plugin.bats | 6 ++--
tests/update.bats | 2 +-
tools/sh.go | 95 +++++++++++++++++++++++++++++++++++++++++++++++++++
tools/tools.go | 20 ++++++++++-
6 files changed, 123 insertions(+), 12 deletions(-)
diff --git a/go.mod b/go.mod
index 14d9b33..f9561ae 100644
--- a/go.mod
+++ b/go.mod
@@ -20,6 +20,7 @@ require (
github.com/nuvolaris/jj v0.0.0-20231020143327-10b90948a5d2
github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c
github.com/sciabarracom/openwhisk-cli v1.2.1
+ github.com/sciabarracom/sh/v3 v3.8.2
github.com/sciabarracom/task/v3 v3.38.9
github.com/stretchr/testify v1.9.0
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8
@@ -84,7 +85,6 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/sajari/fuzzy v1.0.0 // indirect
github.com/sciabarracom/openwhisk-wskdeploy v1.2.1 // indirect
- github.com/sciabarracom/sh/v3 v3.8.2 // indirect
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 // indirect
github.com/skeema/knownhosts v1.2.2 // indirect
github.com/spf13/cobra v1.1.3 // indirect
diff --git a/tests/auto_setup.bats b/tests/auto_setup.bats
index 9982025..173394f 100644
--- a/tests/auto_setup.bats
+++ b/tests/auto_setup.bats
@@ -26,7 +26,7 @@ setup() {
run rm -rf ~/.nuv
run nuv
assert_success
- assert_output --partial "Welcome to nuv! Setting up..."
+ assert_output --partial "Welcome to ops! Setting up..."
run ls ~/.nuv
assert_success
}
@@ -36,17 +36,17 @@ setup() {
export NUV_BRANCH=wrong
run nuv
assert_failure
- assert_output --partial "Welcome to nuv! Setting up..."
+ assert_output --partial "Welcome to ops! Setting up..."
assert_output --partial "failed to clone olaris on branch 'wrong'"
}
@test "correct branch setups" {
run rm -rf ~/.nuv
- export NUV_BRANCH=0.1.0-testing
+ export NUV_BRANCH=0.1.0
run nuv
assert_success
- assert_output --partial "Welcome to nuv! Setting up..."
+ assert_output --partial "Welcome to ops! Setting up..."
run ls ~/.nuv
assert_success
- assert_output --partial "0.1.0-testing"
+ assert_output --partial "0.1.0"
}
diff --git a/tests/plugin.bats b/tests/plugin.bats
index fe5c23d..aa39414 100644
--- a/tests/plugin.bats
+++ b/tests/plugin.bats
@@ -20,6 +20,7 @@ setup() {
load 'test_helper/bats-assert/load'
export NO_COLOR=1
export NUV_BRANCH="$(cat ../branch.txt)"
+ run rm -rf ~/.nuv
}
@test "nuv prints 'Plugins:'" {
@@ -63,7 +64,6 @@ setup() {
run nuv
assert_line 'Plugins:'
assert_line " other (local)"
- run rm -rf ~/.nuv/olaris
}
@test "other sub simple prints simple" {
@@ -71,7 +71,6 @@ setup() {
run nuv -update
run nuv other sub simple
assert_line 'simple'
- run rm -rf ~/.nuv/olaris
}
@test "other tool runs nuv tool" {
@@ -79,7 +78,7 @@ setup() {
run nuv -update
run nuv other tool
assert_line 'hello'
- run rm -rf ~/.nuv/olaris
+ run rm -rf ~/.nuv
}
@test "other command runs nuv command" {
@@ -87,7 +86,6 @@ setup() {
run nuv -update
run nuv other command
assert_line --partial 'nothing installed yet'
- run rm -rf ~/.nuv/olaris
}
# Plugin Tool Tests
diff --git a/tests/update.bats b/tests/update.bats
index 780dcaa..a0721f0 100644
--- a/tests/update.bats
+++ b/tests/update.bats
@@ -49,7 +49,7 @@ setup() {
@test "nuv -update on branch" {
run rm -rf ~/.nuv
- export NUV_BRANCH=0.1.0-testing
+ export NUV_BRANCH=0.1.0
run nuv -update
assert_line "Nuvfiles downloaded successfully"
assert_success
diff --git a/tools/sh.go b/tools/sh.go
new file mode 100644
index 0000000..540b6b3
--- /dev/null
+++ b/tools/sh.go
@@ -0,0 +1,95 @@
+// Copyright (c) 2017, Daniel Martà <mv...@mvdan.cc>
+// See LICENSE for licensing information
+
+// gosh is a proof of concept shell built on top of [interp].
+package tools
+
+import (
+ "context"
+ "fmt"
+ "io"
+ "os"
+
+ "golang.org/x/term"
+
+ "github.com/sciabarracom/sh/v3/interp"
+ "github.com/sciabarracom/sh/v3/syntax"
+)
+
+func Sh() (int, error) {
+ path := ""
+ if len(os.Args) > 1 {
+ path = os.Args[1]
+ if path == "-h" || path == "--help" {
+ fmt.Println("Sh is the mvdan shell using the ops environment.\nUsage: [<script>|-h|--help]\nWithout args starts an interactive shell otherwise execute the script.")
+ return 0, nil
+ }
+ }
+ err := runAll(path)
+ if e, ok := interp.IsExitStatus(err); ok {
+ return int(e), err
+ }
+ if err != nil {
+ return 1, err
+ }
+ return 0, nil
+}
+
+func runAll(path string) error {
+ r, err := interp.New(interp.StdIO(os.Stdin, os.Stdout, os.Stderr))
+ if err != nil {
+ return err
+ }
+
+ if path != "" {
+ return runPath(r, path)
+ }
+ if term.IsTerminal(int(os.Stdin.Fd())) {
+ return runInteractive(r, os.Stdin, os.Stdout, os.Stderr)
+ }
+ return run(r, os.Stdin, "")
+}
+
+func run(r *interp.Runner, reader io.Reader, name string) error {
+ prog, err := syntax.NewParser().Parse(reader, name)
+ if err != nil {
+ return err
+ }
+ r.Reset()
+ ctx := context.Background()
+ return r.Run(ctx, prog)
+}
+
+func runPath(r *interp.Runner, path string) error {
+ f, err := os.Open(path)
+ if err != nil {
+ return err
+ }
+ defer f.Close()
+ return run(r, f, path)
+}
+
+func runInteractive(r *interp.Runner, stdin io.Reader, stdout, stderr io.Writer) error {
+ parser := syntax.NewParser()
+ fmt.Fprintf(stdout, "@ ")
+ var runErr error
+ fn := func(stmts []*syntax.Stmt) bool {
+ if parser.Incomplete() {
+ fmt.Fprintf(stdout, "> ")
+ return true
+ }
+ ctx := context.Background()
+ for _, stmt := range stmts {
+ runErr = r.Run(ctx, stmt)
+ if r.Exited() {
+ return false
+ }
+ }
+ fmt.Fprintf(stdout, "$ ")
+ return true
+ }
+ if err := parser.Interactive(stdin, fn); err != nil {
+ return err
+ }
+ return runErr
+}
diff --git a/tools/tools.go b/tools/tools.go
index 364e7f3..204b7fb 100644
--- a/tools/tools.go
+++ b/tools/tools.go
@@ -42,7 +42,7 @@ func trace(args ...any) {
// available in taskfiles
// note some of them are implemented in main.go (config, retry)
var ToolList = []string{
- "wsk", "awk", "jq",
+ "wsk", "awk", "jq", "sh",
"envsubst", "filetype", "random", "datefmt",
"die", "urlenc", "replace", "base64", "validate",
"echoif", "echoifempty", "echoifexists",
@@ -67,67 +67,85 @@ func RunTool(name string, args []string) (int, error) {
if err := Wsk(cmd); err != nil {
return 1, err
}
+
case "awk":
// fmt.Println("=== awk ===")
os.Args = append([]string{"goawk"}, args...)
if err := goawk.AwkMain(); err != nil {
return 1, err
}
+
case "jq":
os.Args = append([]string{"gojq"}, args...)
return gojq.Run(), nil
+
+ case "sh":
+ os.Args = append([]string{"sh"}, args...)
+ return Sh()
+
case "envsubst":
os.Args = append([]string{"envsubst"}, args...)
if err := envsubst.EnvsubstMain(); err != nil {
return 1, err
}
+
case "filetype":
os.Args = append([]string{"mkdir"}, args...)
if err := Filetype(); err != nil {
return 1, err
}
+
case "random":
if err := RandTool(args...); err != nil {
return 1, err
}
+
case "datefmt":
os.Args = append([]string{"datefmt"}, args...)
if err := DateFmtTool(); err != nil {
return 1, err
}
+
case "die":
if len(args) > 0 {
fmt.Println(strings.Join(args, " "))
}
return 1, nil
+
case "urlenc":
os.Args = append([]string{"urlenc"}, args...)
if err := URLEncTool(); err != nil {
return 1, err
}
+
case "replace":
os.Args = append([]string{"replace"}, args...)
return replace.ReplaceMain()
+
case "base64":
os.Args = append([]string{"base64"}, args...)
if err := base64Tool(); err != nil {
return 1, err
}
+
case "validate":
os.Args = append([]string{"validate"}, args...)
if err := validateTool(); err != nil {
return 1, err
}
+
case "echoif":
os.Args = append([]string{"echoif"}, args...)
if err := echoIfTool(); err != nil {
return 1, err
}
+
case "echoifempty":
os.Args = append([]string{"echoifempty"}, args...)
if err := echoIfEmptyTool(); err != nil {
return 1, err
}
+
case "echoifexists":
os.Args = append([]string{"echoifexists"}, args...)
if err := echoIfExistsTool(); err != nil {