99 "syscall/js"
1010
1111 "github.com/scaleway/scaleway-cli/v2/internal/core"
12+ "github.com/scaleway/scaleway-cli/v2/internal/jshelpers"
1213 "github.com/scaleway/scaleway-cli/v2/internal/namespaces"
14+ "github.com/scaleway/scaleway-cli/v2/internal/platform/web"
1315)
1416
1517var commands * core.Commands
@@ -21,7 +23,11 @@ func getCommands() *core.Commands {
2123 return commands
2224}
2325
24- func runCommand (args []string , stdout io.Writer , stderr io.Writer ) chan int {
26+ type RunConfig struct {
27+ JWT string `js:"jwt"`
28+ }
29+
30+ func runCommand (cfg * RunConfig , args []string , stdout io.Writer , stderr io.Writer ) chan int {
2531 ret := make (chan int , 1 )
2632 go func () {
2733 exitCode , _ , _ := core .Bootstrap (& core.BootstrapConfig {
@@ -31,6 +37,9 @@ func runCommand(args []string, stdout io.Writer, stderr io.Writer) chan int {
3137 Stdout : stdout ,
3238 Stderr : stderr ,
3339 Stdin : nil ,
40+ Platform : & web.Platform {
41+ JWT : cfg .JWT ,
42+ },
3443 })
3544 ret <- exitCode
3645 }()
@@ -43,14 +52,23 @@ func wasmRun(this js.Value, args []js.Value) (any, error) {
4352 stdout := bytes .NewBuffer (nil )
4453 stderr := bytes .NewBuffer (nil )
4554
46- for argIndex , arg := range args {
47- if arg .Type () != js .TypeString {
48- return nil , fmt .Errorf ("invalid argument at index %d" , argIndex )
49- }
50- cliArgs = append (cliArgs , arg .String ())
55+ if len (args ) < 2 {
56+ return nil , fmt .Errorf ("not enough arguments" )
57+ }
58+
59+ runCfg , err := jshelpers.AsObject [RunConfig ](args [0 ])
60+ if err != nil {
61+ return nil , fmt .Errorf ("invalid config given: %w" , err )
62+ }
63+
64+ givenArgs , err := jshelpers.AsSlice [string ](args [1 ])
65+ if err != nil {
66+ return nil , fmt .Errorf ("invalid args given: %w" , err )
5167 }
5268
53- exitCodeChan := runCommand (cliArgs , stdout , stderr )
69+ cliArgs = append (cliArgs , givenArgs ... )
70+
71+ exitCodeChan := runCommand (runCfg , cliArgs , stdout , stderr )
5472 exitCode := <- exitCodeChan
5573 if exitCode != 0 {
5674 errBody := stderr .String ()
@@ -77,5 +95,5 @@ func main() {
7795 givenCallback .Invoke ()
7896 }
7997 }
80- <- make (chan struct {}, 0 )
98+ <- make (chan struct {})
8199}
0 commit comments