sealos-cli 1.1.1 → 1.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sealos-cli",
3
- "version": "1.1.1",
3
+ "version": "1.1.2",
4
4
  "description": "Official CLI tool for Sealos Cloud - Manage auth, workspaces, devboxes, databases, and templates",
5
5
  "types": "dist/main.d.ts",
6
6
  "type": "module",
@@ -76,7 +76,7 @@ export function createAuthCommand (): Command {
76
76
  authCmd
77
77
  .command('list')
78
78
  .description('List all workspaces')
79
- .option('-o, --output <format>', 'Output format: json, table', 'table')
79
+ .option('-o, --output <format>', 'Output format: json, table', 'json')
80
80
  .action(async (options) => {
81
81
  try {
82
82
  const result = await listWorkspaces()
@@ -105,7 +105,7 @@ export function createAuthCommand (): Command {
105
105
  .command('switch')
106
106
  .description('Switch workspace')
107
107
  .argument('<namespace>', 'Workspace id, uid, or team name')
108
- .option('-o, --output <format>', 'Output format: json, table', 'table')
108
+ .option('-o, --output <format>', 'Output format: json, table', 'json')
109
109
  .action(async (namespace, options) => {
110
110
  try {
111
111
  const result = await switchWorkspace(namespace)
@@ -8,7 +8,7 @@ export function createLoginCommand (): Command {
8
8
  .description('Login to Sealos Cloud')
9
9
  .argument('[region]', 'Sealos region URL (e.g., https://usw-1.sealos.io)')
10
10
  .option('-t, --token <token>', 'Store a regional token without OAuth device login')
11
- .option('-o, --output <format>', 'Output format: json, table', 'table')
11
+ .option('-o, --output <format>', 'Output format: json, table', 'json')
12
12
  .action(async (region, options) => {
13
13
  try {
14
14
  const result = options.token
@@ -1,20 +1,39 @@
1
1
  import { Command } from 'commander'
2
2
  import { checkAuth, clearAuth } from '../../lib/auth.ts'
3
- import { success, warn } from '../../lib/output.ts'
3
+ import { outputJson, success, warn } from '../../lib/output.ts'
4
4
  import { handleError } from '../../lib/errors.ts'
5
5
 
6
6
  export function createLogoutCommand (): Command {
7
7
  return new Command('logout')
8
8
  .description('Logout from Sealos Cloud')
9
- .action(async () => {
9
+ .option('-o, --output <format>', 'Output format: json, table', 'json')
10
+ .action(async (options) => {
10
11
  try {
11
12
  const status = checkAuth()
12
13
  if (!status.authenticated) {
14
+ if (options.output === 'json') {
15
+ outputJson({
16
+ success: true,
17
+ action: 'logout',
18
+ authenticated: false,
19
+ changed: false
20
+ })
21
+ return
22
+ }
13
23
  warn('You are not logged in')
14
24
  return
15
25
  }
16
26
 
17
27
  clearAuth()
28
+ if (options.output === 'json') {
29
+ outputJson({
30
+ success: true,
31
+ action: 'logout',
32
+ authenticated: false,
33
+ changed: true
34
+ })
35
+ return
36
+ }
18
37
  success('Logged out from Sealos Cloud')
19
38
  } catch (error) {
20
39
  handleError(error)
@@ -6,7 +6,7 @@ import { handleError, AuthError } from '../../lib/errors.ts'
6
6
  export function createWhoamiCommand (): Command {
7
7
  return new Command('whoami')
8
8
  .description('Display current user information')
9
- .option('-o, --output <format>', 'Output format: json, table', 'table')
9
+ .option('-o, --output <format>', 'Output format: json, table', 'json')
10
10
  .action(async (options) => {
11
11
  try {
12
12
  const authInfo = getAuthInfo()
@@ -268,7 +268,7 @@ export function createDatabaseCommand (): Command {
268
268
  dbCmd
269
269
  .command('list')
270
270
  .description('List databases')
271
- .option('-o, --output <format>', 'Output format (json|table)', 'table')
271
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
272
272
  .action(withAuth({ spinnerText: 'Loading databases...' }, async (ctx, options: { output: string }) => {
273
273
  const client = createDatabaseClient()
274
274
  const { data, error, response } = await client.GET('/databases', {
@@ -319,7 +319,7 @@ export function createDatabaseCommand (): Command {
319
319
  dbCmd
320
320
  .command('versions')
321
321
  .description('List supported database versions (public endpoint)')
322
- .option('-o, --output <format>', 'Output format (json|table)', 'table')
322
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
323
323
  .option('--host <host>', 'Sealos region host for public version lookup, e.g. https://gzg.sealos.run')
324
324
  .option('--type <type>', 'Filter versions by database type')
325
325
  .action(withErrorHandling({ spinnerText: 'Loading versions...' }, async (ctx, options: { output: string; host?: string; type?: string }) => {
@@ -384,7 +384,7 @@ export function createDatabaseCommand (): Command {
384
384
  .option('--backup-save-time <count>', 'Retention count')
385
385
  .option('--backup-save-type <type>', 'Retention unit (days|hours|weeks|months)')
386
386
  .option('--param <KEY=VALUE>', 'Database parameter override', collectOption, [] as string[])
387
- .option('-o, --output <format>', 'Output format (json|table)', 'table')
387
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
388
388
  .action(withAuth({
389
389
  spinnerText: 'Creating database...'
390
390
  }, async (
@@ -452,7 +452,7 @@ export function createDatabaseCommand (): Command {
452
452
  .command('get <name>')
453
453
  .alias('describe')
454
454
  .description('Get database details')
455
- .option('-o, --output <format>', 'Output format (json|table)', 'table')
455
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
456
456
  .action(withAuth({ spinnerText: 'Loading database...' }, async (ctx, name: string, options: { output: string }) => {
457
457
  const client = createDatabaseClient()
458
458
  const { data, error, response } = await client.GET('/databases/{databaseName}', {
@@ -477,7 +477,7 @@ export function createDatabaseCommand (): Command {
477
477
  dbCmd
478
478
  .command('connection <name>')
479
479
  .description('Show database connection details')
480
- .option('-o, --output <format>', 'Output format (json|table)', 'table')
480
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
481
481
  .action(withAuth({ spinnerText: 'Loading connection details...' }, async (ctx, name: string, options: { output: string }) => {
482
482
  const client = createDatabaseClient()
483
483
  const { data, error, response } = await client.GET('/databases/{databaseName}', {
@@ -506,12 +506,13 @@ export function createDatabaseCommand (): Command {
506
506
  .option('--memory <memory>', 'Memory in GB per replica')
507
507
  .option('--storage <storage>', 'Storage in GB per replica')
508
508
  .option('--replicas <replicas>', 'Replica count')
509
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
509
510
  .action(withAuth({
510
511
  spinnerText: 'Updating database...'
511
512
  }, async (
512
513
  ctx,
513
514
  name: string,
514
- options: { cpu?: string; memory?: string; storage?: string; replicas?: string }
515
+ options: { cpu?: string; memory?: string; storage?: string; replicas?: string; output: string }
515
516
  ) => {
516
517
  const quota = buildQuota(options)
517
518
  if (Object.keys(quota).length === 0) {
@@ -529,13 +530,25 @@ export function createDatabaseCommand (): Command {
529
530
 
530
531
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
531
532
 
533
+ if (options.output === 'json') {
534
+ ctx.spinner.stop()
535
+ outputJson({
536
+ success: true,
537
+ action: 'update',
538
+ resource: 'database',
539
+ name,
540
+ status: 'requested'
541
+ })
542
+ return
543
+ }
532
544
  ctx.spinner.succeed(`Database "${name}" update requested`)
533
545
  }))
534
546
 
535
547
  dbCmd
536
548
  .command('start <name>')
537
549
  .description('Start a database')
538
- .action(withAuth({ spinnerText: 'Starting database...' }, async (ctx, name: string) => {
550
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
551
+ .action(withAuth({ spinnerText: 'Starting database...' }, async (ctx, name: string, options: { output: string }) => {
539
552
  const client = createDatabaseClient()
540
553
  const { error, response } = await client.POST('/databases/{databaseName}/start', {
541
554
  headers: ctx.auth,
@@ -545,6 +558,17 @@ export function createDatabaseCommand (): Command {
545
558
  })
546
559
 
547
560
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
561
+ if (options.output === 'json') {
562
+ ctx.spinner.stop()
563
+ outputJson({
564
+ success: true,
565
+ action: 'start',
566
+ resource: 'database',
567
+ name,
568
+ status: 'requested'
569
+ })
570
+ return
571
+ }
548
572
  ctx.spinner.succeed(`Database "${name}" start requested`)
549
573
  }))
550
574
 
@@ -552,7 +576,8 @@ export function createDatabaseCommand (): Command {
552
576
  .command('pause <name>')
553
577
  .alias('stop')
554
578
  .description('Pause a database')
555
- .action(withAuth({ spinnerText: 'Pausing database...' }, async (ctx, name: string) => {
579
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
580
+ .action(withAuth({ spinnerText: 'Pausing database...' }, async (ctx, name: string, options: { output: string }) => {
556
581
  const client = createDatabaseClient()
557
582
  const { error, response } = await client.POST('/databases/{databaseName}/pause', {
558
583
  headers: ctx.auth,
@@ -562,13 +587,25 @@ export function createDatabaseCommand (): Command {
562
587
  })
563
588
 
564
589
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
590
+ if (options.output === 'json') {
591
+ ctx.spinner.stop()
592
+ outputJson({
593
+ success: true,
594
+ action: 'pause',
595
+ resource: 'database',
596
+ name,
597
+ status: 'requested'
598
+ })
599
+ return
600
+ }
565
601
  ctx.spinner.succeed(`Database "${name}" pause requested`)
566
602
  }))
567
603
 
568
604
  dbCmd
569
605
  .command('restart <name>')
570
606
  .description('Restart a database')
571
- .action(withAuth({ spinnerText: 'Restarting database...' }, async (ctx, name: string) => {
607
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
608
+ .action(withAuth({ spinnerText: 'Restarting database...' }, async (ctx, name: string, options: { output: string }) => {
572
609
  const client = createDatabaseClient()
573
610
  const { error, response } = await client.POST('/databases/{databaseName}/restart', {
574
611
  headers: ctx.auth,
@@ -578,6 +615,17 @@ export function createDatabaseCommand (): Command {
578
615
  })
579
616
 
580
617
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
618
+ if (options.output === 'json') {
619
+ ctx.spinner.stop()
620
+ outputJson({
621
+ success: true,
622
+ action: 'restart',
623
+ resource: 'database',
624
+ name,
625
+ status: 'requested'
626
+ })
627
+ return
628
+ }
581
629
  ctx.spinner.succeed(`Database "${name}" restart requested`)
582
630
  }))
583
631
 
@@ -585,7 +633,8 @@ export function createDatabaseCommand (): Command {
585
633
  .command('delete <name>')
586
634
  .description('Delete a database')
587
635
  .option('-f, --force', 'Delete without confirmation')
588
- .action(withAuth({ spinnerText: 'Deleting database...' }, async (ctx, name: string) => {
636
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
637
+ .action(withAuth({ spinnerText: 'Deleting database...' }, async (ctx, name: string, options: { output: string }) => {
589
638
  const client = createDatabaseClient()
590
639
  const { error, response } = await client.DELETE('/databases/{databaseName}', {
591
640
  headers: ctx.auth,
@@ -595,13 +644,24 @@ export function createDatabaseCommand (): Command {
595
644
  })
596
645
 
597
646
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
647
+ if (options.output === 'json') {
648
+ ctx.spinner.stop()
649
+ outputJson({
650
+ success: true,
651
+ action: 'delete',
652
+ resource: 'database',
653
+ name,
654
+ status: 'requested'
655
+ })
656
+ return
657
+ }
598
658
  ctx.spinner.succeed(`Database "${name}" delete requested`)
599
659
  }))
600
660
 
601
661
  dbCmd
602
662
  .command('backups <name>')
603
663
  .description('List backups for a database')
604
- .option('-o, --output <format>', 'Output format (json|table)', 'table')
664
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
605
665
  .action(withAuth({ spinnerText: 'Loading backups...' }, async (ctx, name: string, options: { output: string }) => {
606
666
  const client = createDatabaseClient()
607
667
  const { data, error, response } = await client.GET('/databases/{databaseName}/backups', {
@@ -649,12 +709,13 @@ export function createDatabaseCommand (): Command {
649
709
  .description('Create a database backup')
650
710
  .option('--name <backupName>', 'Backup name')
651
711
  .option('--description <description>', 'Backup description')
712
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
652
713
  .action(withAuth({
653
714
  spinnerText: 'Creating backup...'
654
715
  }, async (
655
716
  ctx,
656
717
  name: string,
657
- options: { name?: string; description?: string }
718
+ options: { name?: string; description?: string; output: string }
658
719
  ) => {
659
720
  const client = createDatabaseClient()
660
721
  const body: Record<string, string> = {}
@@ -670,15 +731,28 @@ export function createDatabaseCommand (): Command {
670
731
  })
671
732
 
672
733
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
734
+ if (options.output === 'json') {
735
+ ctx.spinner.stop()
736
+ outputJson({
737
+ success: true,
738
+ action: 'backup',
739
+ resource: 'database',
740
+ name,
741
+ backupName: options.name ?? null,
742
+ status: 'requested'
743
+ })
744
+ return
745
+ }
673
746
  ctx.spinner.succeed(`Backup requested for database "${name}"`)
674
747
  }))
675
748
 
676
749
  dbCmd
677
750
  .command('backup-delete <databaseName> <backupName>')
678
751
  .description('Delete a database backup')
752
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
679
753
  .action(withAuth({
680
754
  spinnerText: 'Deleting backup...'
681
- }, async (ctx, databaseName: string, backupName: string) => {
755
+ }, async (ctx, databaseName: string, backupName: string, options: { output: string }) => {
682
756
  const client = createDatabaseClient()
683
757
  const { error, response } = await client.DELETE('/databases/{databaseName}/backups/{backupName}', {
684
758
  headers: ctx.auth,
@@ -688,6 +762,18 @@ export function createDatabaseCommand (): Command {
688
762
  })
689
763
 
690
764
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
765
+ if (options.output === 'json') {
766
+ ctx.spinner.stop()
767
+ outputJson({
768
+ success: true,
769
+ action: 'backup-delete',
770
+ resource: 'database-backup',
771
+ databaseName,
772
+ backupName,
773
+ status: 'deleted'
774
+ })
775
+ return
776
+ }
691
777
  ctx.spinner.succeed(`Backup "${backupName}" deleted`)
692
778
  }))
693
779
 
@@ -697,12 +783,13 @@ export function createDatabaseCommand (): Command {
697
783
  .requiredOption('--from <backupName>', 'Backup name to restore from')
698
784
  .option('--name <name>', 'Name for the restored database')
699
785
  .option('--replicas <replicas>', 'Replica count for the restored database')
786
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
700
787
  .action(withAuth({
701
788
  spinnerText: 'Restoring database...'
702
789
  }, async (
703
790
  ctx,
704
791
  databaseName: string,
705
- options: { from: string; name?: string; replicas?: string }
792
+ options: { from: string; name?: string; replicas?: string; output: string }
706
793
  ) => {
707
794
  const client = createDatabaseClient()
708
795
  const body: Record<string, unknown> = {}
@@ -718,13 +805,27 @@ export function createDatabaseCommand (): Command {
718
805
  })
719
806
 
720
807
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
808
+ if (options.output === 'json') {
809
+ ctx.spinner.stop()
810
+ outputJson({
811
+ success: true,
812
+ action: 'restore',
813
+ resource: 'database',
814
+ databaseName,
815
+ backupName: options.from,
816
+ restoredName: options.name ?? null,
817
+ status: 'requested'
818
+ })
819
+ return
820
+ }
721
821
  ctx.spinner.succeed(`Restore requested from backup "${options.from}"`)
722
822
  }))
723
823
 
724
824
  dbCmd
725
825
  .command('enable-public <name>')
726
826
  .description('Enable public access for a database')
727
- .action(withAuth({ spinnerText: 'Enabling public access...' }, async (ctx, name: string) => {
827
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
828
+ .action(withAuth({ spinnerText: 'Enabling public access...' }, async (ctx, name: string, options: { output: string }) => {
728
829
  const client = createDatabaseClient()
729
830
  const { error, response } = await client.POST('/databases/{databaseName}/enable-public', {
730
831
  headers: ctx.auth,
@@ -734,13 +835,25 @@ export function createDatabaseCommand (): Command {
734
835
  })
735
836
 
736
837
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
838
+ if (options.output === 'json') {
839
+ ctx.spinner.stop()
840
+ outputJson({
841
+ success: true,
842
+ action: 'enable-public',
843
+ resource: 'database',
844
+ name,
845
+ status: 'enabled'
846
+ })
847
+ return
848
+ }
737
849
  ctx.spinner.succeed(`Public access enabled for "${name}"`)
738
850
  }))
739
851
 
740
852
  dbCmd
741
853
  .command('disable-public <name>')
742
854
  .description('Disable public access for a database')
743
- .action(withAuth({ spinnerText: 'Disabling public access...' }, async (ctx, name: string) => {
855
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
856
+ .action(withAuth({ spinnerText: 'Disabling public access...' }, async (ctx, name: string, options: { output: string }) => {
744
857
  const client = createDatabaseClient()
745
858
  const { error, response } = await client.POST('/databases/{databaseName}/disable-public', {
746
859
  headers: ctx.auth,
@@ -750,6 +863,17 @@ export function createDatabaseCommand (): Command {
750
863
  })
751
864
 
752
865
  if (error) throw mapApiError(response.status, error as ApiErrorBody)
866
+ if (options.output === 'json') {
867
+ ctx.spinner.stop()
868
+ outputJson({
869
+ success: true,
870
+ action: 'disable-public',
871
+ resource: 'database',
872
+ name,
873
+ status: 'disabled'
874
+ })
875
+ return
876
+ }
753
877
  ctx.spinner.succeed(`Public access disabled for "${name}"`)
754
878
  }))
755
879
 
@@ -761,7 +885,7 @@ export function createDatabaseCommand (): Command {
761
885
  .requiredOption('--log-path <path>', 'Log path to read. Use "log-files" first to discover valid paths')
762
886
  .option('--page <page>', 'Page number', '1')
763
887
  .option('--page-size <pageSize>', 'Page size', '200')
764
- .option('-o, --output <format>', 'Output format (plain|json|table)', 'plain')
888
+ .option('-o, --output <format>', 'Output format (json|table|plain)', 'json')
765
889
  .action(withAuth({
766
890
  spinnerText: 'Loading logs...'
767
891
  }, async (
@@ -820,7 +944,7 @@ export function createDatabaseCommand (): Command {
820
944
  .description('List database log files for a pod')
821
945
  .requiredOption('--db-type <type>', 'Database type used by the log service')
822
946
  .requiredOption('--log-type <type>', 'Log type used by the log service')
823
- .option('-o, --output <format>', 'Output format (json|table)', 'table')
947
+ .option('-o, --output <format>', 'Output format (json|table)', 'json')
824
948
  .action(withAuth({
825
949
  spinnerText: 'Loading log files...'
826
950
  }, async (