Skip to content

Commit 2f1c209

Browse files
committed
Merge branch 'add_validate_config' of github.com:yfodil/scaleway-cli into add_validate_config
2 parents 19c61bb + f8f04f8 commit 2f1c209

File tree

572 files changed

+49258
-8734
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

572 files changed

+49258
-8734
lines changed

.github/workflows/unit-tests.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ jobs:
4646
fetch-depth: 1
4747
- name: Build binaries
4848
run: ./scripts/build.sh
49+
- name: Print binaries size
50+
run: ls -lh ./bin
51+
- name: Check binary size
52+
run: ./scripts/check-size.sh ./bin/*linux-x86_64
4953

5054
docker-tests:
5155
runs-on: ubuntu-latest

.github/workflows/wasm.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: WebAssembly
2+
3+
on:
4+
pull_request:
5+
merge_group:
6+
7+
jobs:
8+
build-and-test:
9+
strategy:
10+
matrix:
11+
go-version: [1.19.x]
12+
platform: [ubuntu-latest]
13+
runs-on: ${{ matrix.platform }}
14+
steps:
15+
- name: Install Go
16+
uses: actions/setup-go@v3
17+
with:
18+
go-version: ${{ matrix.go-version }}
19+
- name: Install pnpm
20+
uses: pnpm/action-setup@v2
21+
with:
22+
version: 6.0.2
23+
- name: Checkout
24+
uses: actions/checkout@v3
25+
with:
26+
fetch-depth: 1
27+
- name: Build
28+
run: ./scripts/build-wasm.sh
29+
- name: Run npm package tests
30+
run: ./scripts/run-tests-wasm.sh

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ builds:
2222
- goos: darwin
2323
goarch: 386
2424
ldflags:
25+
- -s -w
2526
- -X main.Version={{ .Version }}
2627
- -X main.BuildDate={{ .Date }}
2728
- -X main.GitBranch={{ .Branch }}

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ To enable beta features, you can set `SCW_ENABLE_BETA=1` in your environment.
120120
| `applesilicon` | Apple silicon API | [CLI](./docs/commands/apple-silicon.md) / [API](https://developers.scaleway.com/en/products/apple-silicon/api/) |
121121
| `autocomplete` | Autocomplete related commands | [CLI](./docs/commands/autocomplete.md) |
122122
| `baremetal` | Baremetal API | [CLI](./docs/commands/baremetal.md) / [API](https://developers.scaleway.com/en/products/baremetal/api/) |
123+
| `billing` | Billing API | [CLI](./docs/commands/billing.md) / [API](https://developers.scaleway.com/en/products/billing/api/) |
123124
| `cockpit` | Cockpit API | [CLI](./docs/commands/cockpit.md) / [API](https://developers.scaleway.com/en/products/cockpit/api/) |
124125
| `config` | Config file management | [CLI](./docs/commands/config.md) |
125126
| `container` | Serverless Container API | [CLI](./docs/commands/container.md) / [API](https://developers.scaleway.com/en/products/containers/api/) |

cmd/scw-wasm/args.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//go:build wasm && js
2+
3+
package main
4+
5+
import (
6+
"os"
7+
)
8+
9+
type Args struct {
10+
callback string
11+
targetObject string
12+
}
13+
14+
func getArgs() Args {
15+
args := Args{}
16+
if len(os.Args) > 0 {
17+
args.callback = os.Args[0]
18+
}
19+
if len(os.Args) > 1 {
20+
args.targetObject = os.Args[1]
21+
}
22+
23+
return args
24+
}

cmd/scw-wasm/async.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
//go:build wasm && js
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"runtime/debug"
8+
"syscall/js"
9+
10+
"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
11+
)
12+
13+
type fn func(this js.Value, args []js.Value) (any, error)
14+
15+
var (
16+
jsErr = js.Global().Get("Error")
17+
jsPromise = js.Global().Get("Promise")
18+
)
19+
20+
func asyncFunc(innerFunc fn) js.Func {
21+
return js.FuncOf(func(this js.Value, args []js.Value) any {
22+
handler := js.FuncOf(func(_ js.Value, promFn []js.Value) any {
23+
resolve, reject := promFn[0], promFn[1]
24+
25+
go func() {
26+
defer func() {
27+
if r := recover(); r != nil {
28+
reject.Invoke(jshelpers.NewError(
29+
fmt.Sprintf("panic: %v\n%s", r, string(debug.Stack())),
30+
))
31+
}
32+
}()
33+
34+
res, err := innerFunc(this, args)
35+
if err != nil {
36+
reject.Invoke(jshelpers.NewError(err.Error()))
37+
} else {
38+
resolve.Invoke(res)
39+
}
40+
}()
41+
42+
return nil
43+
})
44+
45+
return jsPromise.New(handler)
46+
})
47+
}

cmd/scw-wasm/main.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//go:build wasm && js
2+
3+
package main
4+
5+
import (
6+
"syscall/js"
7+
8+
"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
9+
"github.com/scaleway/scaleway-cli/v2/internal/wasm"
10+
)
11+
12+
func main() {
13+
args := getArgs()
14+
15+
if args.targetObject != "" {
16+
cliPackage := js.ValueOf(map[string]any{})
17+
cliPackage.Set("run", asyncFunc(jshelpers.AsFunction(wasm.Run)))
18+
js.Global().Set(args.targetObject, cliPackage)
19+
}
20+
21+
if args.callback != "" {
22+
givenCallback := js.Global().Get(args.callback)
23+
if !givenCallback.IsUndefined() {
24+
givenCallback.Invoke()
25+
}
26+
}
27+
<-make(chan struct{})
28+
}

cmd/scw-wasm/run.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//go:build wasm && js
2+
3+
package main
4+
5+
import (
6+
"fmt"
7+
"syscall/js"
8+
9+
"github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
10+
"github.com/scaleway/scaleway-cli/v2/internal/wasm"
11+
)
12+
13+
func wasmRun(this js.Value, args []js.Value) (any, error) {
14+
if len(args) < 2 {
15+
return nil, fmt.Errorf("not enough arguments")
16+
}
17+
18+
runCfg, err := jshelpers.AsObject[wasm.RunConfig](args[0])
19+
if err != nil {
20+
return nil, fmt.Errorf("invalid config given: %w", err)
21+
}
22+
23+
givenArgs, err := jshelpers.AsSlice[string](args[1])
24+
if err != nil {
25+
return nil, fmt.Errorf("invalid args given: %w", err)
26+
}
27+
28+
resp, err := wasm.Run(runCfg, givenArgs)
29+
30+
return jshelpers.FromObject(resp), nil
31+
}

cmd/scw/main.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/mattn/go-colorable"
1111
"github.com/scaleway/scaleway-cli/v2/internal/core"
1212
"github.com/scaleway/scaleway-cli/v2/internal/namespaces"
13+
"github.com/scaleway/scaleway-cli/v2/internal/platform/terminal"
1314
"github.com/scaleway/scaleway-cli/v2/internal/sentry"
1415
"github.com/scaleway/scaleway-sdk-go/scw"
1516
)
@@ -76,6 +77,7 @@ func main() {
7677
Stderr: colorable.NewColorableStderr(),
7778
Stdin: os.Stdin,
7879
BetaMode: BetaMode,
80+
Platform: terminal.NewPlatform(buildInfo.GetUserAgent()),
7981
})
8082

8183
os.Exit(exitCode)

cmd/scw/testdata/test-all-usage-account-project-create-usage.golden

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ USAGE:
66
scw account project create [arg=value ...]
77

88
ARGS:
9-
[name] Name of the Project
10-
[description] Description of the Project
11-
[organization-id] Organization ID to use. If none is passed the default organization ID will be used
9+
[name=<generated>] Name of the Project
10+
[description] Description of the Project
11+
[organization-id] Organization ID to use. If none is passed the default organization ID will be used
1212

1313
FLAGS:
1414
-h, --help help for create

0 commit comments

Comments
 (0)