File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -76,7 +76,7 @@ async function listInstancesAction({
7676 } else {
7777 const table = new Table ( {
7878 head : tableHeaders ,
79- colWidths : [ 32 , 10 , 20 ] ,
79+ // colWidths: [32, 10, 20],
8080 } ) ;
8181
8282 table . push (
@@ -87,7 +87,11 @@ async function listInstancesAction({
8787 instance . status ,
8888 ] ) ,
8989 ) ;
90- console . log ( table . toString ( ) + "\n\n" ) ;
90+ console . log (
91+ table . toString ( ) +
92+ "\n" +
93+ "To ssh into an instance, run `sf ssh <instance-id>`.\n" ,
94+ ) ;
9195 }
9296 }
9397
@@ -152,7 +156,7 @@ const colorInstanceType = (instanceType: InstanceType) =>
152156
153157// --
154158
155- async function getInstances ( {
159+ export async function getInstances ( {
156160 clusterId,
157161} : { clusterId ?: string } ) : Promise < InstanceObject [ ] > {
158162 const loggedIn = await isLoggedIn ( ) ;
Original file line number Diff line number Diff line change 1+ import { $ } from "bun" ;
12import type { Command } from "commander" ;
23import { apiClient } from "../apiClient" ;
34import { isLoggedIn } from "../helpers/config" ;
45import { logAndQuit , logLoginMessageAndQuit } from "../helpers/errors" ;
6+ import { getInstances } from "./instances" ;
57
68function isPubkey ( key : string ) : boolean {
79 const pubKeyPattern = / ^ s s h - / ;
@@ -55,6 +57,25 @@ export function registerSSH(program: Command) {
5557 return ;
5658 }
5759
60+ if ( options . add && name ) {
61+ logAndQuit ( "You can only add a key to all nodes at once" ) ;
62+ }
63+
64+ if ( name ) {
65+ const instances = await getInstances ( { clusterId : undefined } ) ;
66+ const instance = instances . find ( ( instance ) => instance . id === name ) ;
67+ if ( ! instance ) {
68+ logAndQuit ( `Instance ${ name } not found` ) ;
69+ }
70+ if ( instance . ip . split ( ":" ) . length === 2 ) {
71+ const [ ip , port ] = instance . ip . split ( ":" ) ;
72+ await $ `ssh -p ${ port } ${ options . user } @${ ip } ` ;
73+ } else {
74+ await $ `ssh ${ options . user } @${ instance . ip } ` ;
75+ }
76+ process . exit ( 0 ) ;
77+ }
78+
5879 if ( options . add ) {
5980 if ( ! options . user ) {
6081 logAndQuit (
You can’t perform that action at this time.
0 commit comments