11/* eslint-disable no-console */
2+ import { PostDisconnectPayload } from "@scramjet/types/src/rest-api-manager" ;
23import { CommandDefinition , isProductionEnv } from "../../types" ;
34import { profileManager , sessionConfig } from "../config" ;
45import { displayObject , displayStream } from "../output" ;
@@ -79,6 +80,32 @@ export const space: CommandDefinition = (program) => {
7980 await displayStream ( await managerClient . getLogStream ( ) ) ;
8081 } ) ;
8182
83+ spaceCmd
84+ . command ( "disconnect" )
85+ . description ( "Disconnect self hosted Hubs from space" )
86+ . argument ( "<space_name>" , "The name of the Space" )
87+ . option ( "--id <id>" , "Hub Id" )
88+ . option ( "--all" , "Disconnects all self-hosted Hubs connected to Space" , false )
89+ . action ( async ( spaceName : string , id : string , all : string ) => {
90+ const mwClient = getMiddlewareClient ( ) ;
91+ const managerClient = mwClient . getManagerClient ( spaceName ) ;
92+ let opts = { } as PostDisconnectPayload ;
93+
94+ if ( typeof id === "string" ) {
95+ opts = { id } ;
96+ }
97+
98+ if ( all ) {
99+ opts = { limit : 0 } ;
100+ }
101+
102+ if ( ! Object . keys ( opts ) . length ) {
103+ throw new Error ( "Missing --id or --all" ) ;
104+ }
105+
106+ displayObject ( await managerClient . disconnectHubs ( opts ) , profileManager . getProfileConfig ( ) . format ) ;
107+ } ) ;
108+
82109 const accessKeyCmd = spaceCmd
83110 . command ( "access" )
84111 . description ( "Manages Access Keys for active Space" ) ;
@@ -94,7 +121,7 @@ export const space: CommandDefinition = (program) => {
94121 throw new Error ( "No Space set" ) ;
95122 }
96123
97- displayObject ( await mwClient . createAccessKey ( spaceName , { description } ) , "json" ) ;
124+ displayObject ( await mwClient . createAccessKey ( spaceName , { description } ) , profileManager . getProfileConfig ( ) . format ) ;
98125 } ) ;
99126
100127 accessKeyCmd . command ( "list" )
@@ -108,7 +135,7 @@ export const space: CommandDefinition = (program) => {
108135 throw new Error ( "No Space set" ) ;
109136 }
110137
111- displayObject ( await mwClient . listAccessKeys ( spaceName ) , "json" ) ;
138+ displayObject ( await mwClient . listAccessKeys ( spaceName ) , profileManager . getProfileConfig ( ) . format ) ;
112139 } ) ;
113140
114141 accessKeyCmd . command ( "revoke" )
@@ -122,6 +149,6 @@ export const space: CommandDefinition = (program) => {
122149 throw new Error ( "No Space set" ) ;
123150 }
124151
125- displayObject ( await mwClient . revokeAccessKey ( spaceName , accessKey ) , "json" ) ;
152+ displayObject ( await mwClient . revokeAccessKey ( spaceName , accessKey ) , profileManager . getProfileConfig ( ) . format ) ;
126153 } ) ;
127154} ;
0 commit comments