Sitelet https://github.com/NodeOps-app/createos-cli/commit/05f45b65bb96d28f6f705e1745abdec916e91743
Skip to content

Commit 05f45b6

Browse files
fix(network): ask for network before device in attach/detach
Swap the interactive prompt order and positional arg order so the network is selected first, then the sandbox or device. Updates ArgsUsage, usage hints, and README examples to match.
1 parent 0da567d commit 05f45b6

2 files changed

Lines changed: 29 additions & 29 deletions

File tree

‎README.md‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,8 @@ Sandboxes are fast-booting VMs — isolated environments you can exec into, sync
340340
| `createos sandbox network create <name>` | Create a private network |
341341
| `createos sandbox network ls` | List your networks |
342342
| `createos sandbox network show <name\|id>` | Show a network and its attached sandboxes |
343-
| `createos sandbox network attach <sb> <net>` | Add a sandbox to a network |
344-
| `createos sandbox network detach <sb> <net>` | Remove a sandbox from a network |
343+
| `createos sandbox network attach <net> <sb>` | Add a sandbox to a network |
344+
| `createos sandbox network detach <net> <sb>` | Remove a sandbox from a network |
345345
| `createos sandbox network rm <name\|id>` | Delete a network (auto-detaches first) |
346346
| `createos sandbox firewall show <sandbox>` | Show what the sandbox is allowed to reach |
347347
| `createos sandbox firewall set <sb> <host…>` | Replace the outbound allowlist |
@@ -523,8 +523,8 @@ createos sandbox disk rm my-data --yes
523523
# Sandbox networks
524524
createos sandbox network create my-net
525525
createos sandbox network ls
526-
createos sandbox network attach my-box my-net
527-
createos sandbox network detach my-box my-net --yes
526+
createos sandbox network attach my-net my-box
527+
createos sandbox network detach my-net my-box --yes
528528
createos sandbox network rm my-net --yes
529529

530530
# Sandbox firewall

‎cmd/sandbox/network.go‎

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func runNetworkCreate(c *cli.Context) error {
7171
output.Render(c, n, func() {
7272
pterm.Success.Printfln("Created network %s (%s)", n.Name, n.ID)
7373
pterm.Println(pterm.Gray(" Attach at create time: createos sandbox create --network " + n.Name))
74-
pterm.Println(pterm.Gray(" Or live-attach later: createos sandbox network attach <sandbox> " + n.Name))
74+
pterm.Println(pterm.Gray(" Or live-attach later: createos sandbox network attach " + n.Name + " <sandbox>"))
7575
})
7676
return nil
7777
}
@@ -315,7 +315,7 @@ func newNetworkAttachCommand() *cli.Command {
315315
return &cli.Command{
316316
Name: "attach",
317317
Usage: "Add a sandbox or device to a network",
318-
ArgsUsage: "[<sandbox|device> <network>]",
318+
ArgsUsage: "[<network> <sandbox|device>]",
319319
Action: runNetworkAttach,
320320
}
321321
}
@@ -334,41 +334,41 @@ func runNetworkAttach(c *cli.Context) error {
334334
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
335335
}
336336
args := c.Args().Slice()
337-
ref, netRef := "", ""
337+
netRef, ref := "", ""
338338
if len(args) > 0 {
339-
ref = args[0]
339+
netRef = args[0]
340340
}
341341
if len(args) > 1 {
342-
netRef = args[1]
342+
ref = args[1]
343343
}
344344
tty := terminal.IsInteractive()
345-
if ref == "" {
345+
if netRef == "" {
346346
if !tty {
347-
return fmt.Errorf("usage: createos sandbox network attach <sandbox|device> <network>")
347+
return fmt.Errorf("usage: createos sandbox network attach <network> <sandbox|device>")
348348
}
349-
picked, err := pickEndpoint(c, client, "Attach what?")
349+
picked, err := pickNetwork(c, client, "Attach to which network?")
350350
if err != nil {
351351
return err
352352
}
353353
if picked == "" {
354354
fmt.Println("Cancelled.")
355355
return nil
356356
}
357-
ref = picked
357+
netRef = picked
358358
}
359-
if netRef == "" {
359+
if ref == "" {
360360
if !tty {
361-
return fmt.Errorf("usage: createos sandbox network attach <sandbox|device> <network>")
361+
return fmt.Errorf("usage: createos sandbox network attach <network> <sandbox|device>")
362362
}
363-
picked, err := pickNetwork(c, client, "Attach to which network?")
363+
picked, err := pickEndpoint(c, client, "Attach what?")
364364
if err != nil {
365365
return err
366366
}
367367
if picked == "" {
368368
fmt.Println("Cancelled.")
369369
return nil
370370
}
371-
netRef = picked
371+
ref = picked
372372
}
373373
if isDeviceRef(ref) {
374374
if err := client.AttachDeviceToNetwork(c.Context, ref, netRef); err != nil {
@@ -396,7 +396,7 @@ func newNetworkDetachCommand() *cli.Command {
396396
return &cli.Command{
397397
Name: "detach",
398398
Usage: "Remove a sandbox or device from a network",
399-
ArgsUsage: "[<sandbox|device> <network>]",
399+
ArgsUsage: "[<network> <sandbox|device>]",
400400
Flags: []cli.Flag{
401401
&cli.BoolFlag{Name: "yes", Aliases: []string{"y"}, Usage: "Skip the confirmation prompt"},
402402
},
@@ -410,41 +410,41 @@ func runNetworkDetach(c *cli.Context) error {
410410
return fmt.Errorf("you're not signed in — run 'createos login' to get started")
411411
}
412412
args := c.Args().Slice()
413-
ref, netRef := "", ""
413+
netRef, ref := "", ""
414414
if len(args) > 0 {
415-
ref = args[0]
415+
netRef = args[0]
416416
}
417417
if len(args) > 1 {
418-
netRef = args[1]
418+
ref = args[1]
419419
}
420420
tty := terminal.IsInteractive()
421-
if ref == "" {
421+
if netRef == "" {
422422
if !tty {
423-
return fmt.Errorf("usage: createos sandbox network detach <sandbox|device> <network>")
423+
return fmt.Errorf("usage: createos sandbox network detach <network> <sandbox|device>")
424424
}
425-
picked, err := pickEndpoint(c, client, "Detach what?")
425+
picked, err := pickNetwork(c, client, "Detach from which network?")
426426
if err != nil {
427427
return err
428428
}
429429
if picked == "" {
430430
fmt.Println("Cancelled.")
431431
return nil
432432
}
433-
ref = picked
433+
netRef = picked
434434
}
435-
if netRef == "" {
435+
if ref == "" {
436436
if !tty {
437-
return fmt.Errorf("usage: createos sandbox network detach <sandbox|device> <network>")
437+
return fmt.Errorf("usage: createos sandbox network detach <network> <sandbox|device>")
438438
}
439-
picked, err := pickNetwork(c, client, "Detach from which network?")
439+
picked, err := pickEndpoint(c, client, "Detach what?")
440440
if err != nil {
441441
return err
442442
}
443443
if picked == "" {
444444
fmt.Println("Cancelled.")
445445
return nil
446446
}
447-
netRef = picked
447+
ref = picked
448448
}
449449
force := c.Bool("yes")
450450
if !tty && !force {

0 commit comments

Comments
 (0)