@@ -18,71 +18,87 @@ import { SshClientCache } from "./SshClientCache";
1818import { SshErrorHandler } from "./SshErrorHandler" ;
1919import { deployWithProgress } from "./ServerDeployment" ;
2020
21- export function registerCommands ( context : vscode . ExtensionContext , zoweExplorerApi : IApiExplorerExtender ) : vscode . Disposable [ ] {
22- const profCache = zoweExplorerApi . getProfilesCache ( ) ;
23- return [
24- vscode . commands . registerCommand ( `zowe.zowex.connect` , async ( profName ?: string ) => {
25- imperative . Logger . getAppLogger ( ) . trace ( "Running connect command for profile %s" , profName ) ;
26- const vscePromptApi = new VscePromptApi ( await profCache . getProfileInfo ( ) ) ;
27- const profile = await vscePromptApi . promptForProfile ( profName , { prioritizeProjectLevelConfig : false } ) ;
28- if ( ! profile ?. profile ) {
29- return ;
30- }
31- const defaultServerPath = ConfigUtils . getServerPath ( profile . profile ) ;
32- const deployDirectory = await vscePromptApi . promptForDeployDirectory ( profile . profile . host , defaultServerPath ) ;
33- if ( ! deployDirectory ) {
34- return ;
35- }
21+ export class Utilities {
22+ public static registerCommands ( _context : vscode . ExtensionContext , zoweExplorerApi : IApiExplorerExtender ) : vscode . Disposable [ ] {
23+ return [
24+ vscode . commands . registerCommand ( `zowe.zowex.connect` , async ( profName ?: string ) => {
25+ await Utilities . connectCallback ( zoweExplorerApi , profName ) ;
26+ } ) ,
27+ vscode . commands . registerCommand ( `zowe.zowex.restart` , async ( profName ?: string ) => {
28+ await Utilities . restartCallback ( zoweExplorerApi , profName ) ;
29+ } ) ,
30+ vscode . commands . registerCommand ( `zowe.zowex.uninstall` , async ( profName ?: string ) => {
31+ await Utilities . uninstallCallback ( zoweExplorerApi , profName ) ;
32+ } ) ,
33+ ] ;
34+ }
3635
37- const sshSession = ZSshUtils . buildSession ( profile . profile ) ;
38- const deployStatus = await deployWithProgress ( sshSession , deployDirectory ) ;
39- if ( ! deployStatus ) {
40- return ;
41- }
36+ private static async connectCallback ( zoweExplorerApi : IApiExplorerExtender , profName ?: string ) : Promise < void > {
37+ imperative . Logger . getAppLogger ( ) . trace ( "Running connect command for profile %s" , profName ) ;
38+ const profCache = zoweExplorerApi . getProfilesCache ( ) ;
39+ const vscePromptApi = new VscePromptApi ( await profCache . getProfileInfo ( ) ) ;
40+ const profile = await vscePromptApi . promptForProfile ( profName , { prioritizeProjectLevelConfig : false } ) ;
41+ if ( ! profile ?. profile ) {
42+ return ;
43+ }
44+ const defaultServerPath = ConfigUtils . getServerPath ( profile . profile ) ;
45+ const deployDirectory = await vscePromptApi . promptForDeployDirectory ( profile . profile . host , defaultServerPath ) ;
46+ if ( ! deployDirectory ) {
47+ return ;
48+ }
4249
43- await ConfigUtils . showSessionInTree ( profile . name ! , true , zoweExplorerApi ) ;
44- const infoMsg = `Installed Zowe Remote SSH server on ${ ( profile . profile . host as string ) ?? profile . name } ` ;
45- imperative . Logger . getAppLogger ( ) . info ( infoMsg ) ;
46- await Gui . showMessage ( infoMsg ) ;
47- } ) ,
48- vscode . commands . registerCommand ( `zowe.zowex.restart` , async ( profName ?: string ) => {
49- imperative . Logger . getAppLogger ( ) . trace ( "Running restart command for profile %s" , profName ) ;
50- const vscePromptApi = new VscePromptApi ( await profCache . getProfileInfo ( ) ) ;
51- const profile = await vscePromptApi . promptForProfile ( profName , { prioritizeProjectLevelConfig : false , disableCreateNewProfile : true } ) ;
52- if ( ! profile ?. profile ) {
53- return ;
54- }
50+ const sshSession = ZSshUtils . buildSession ( profile . profile ) ;
51+ const deployStatus = await deployWithProgress ( sshSession , deployDirectory ) ;
52+ if ( ! deployStatus ) {
53+ return ;
54+ }
5555
56- await SshClientCache . inst . connect ( profile , { restart : true , retryRequests : false } ) ;
56+ await ConfigUtils . showSessionInTree ( profile . name ! , true , zoweExplorerApi ) ;
57+ const infoMsg = `Installed Zowe Remote SSH server on ${ ( profile . profile . host as string ) ?? profile . name } ` ;
58+ imperative . Logger . getAppLogger ( ) . info ( infoMsg ) ;
59+ await Gui . showMessage ( infoMsg ) ;
60+ }
5761
58- imperative . Logger . getAppLogger ( ) . info ( `Restarted Zowe Remote SSH server on ${ ( profile . profile ?. host as string ) ?? profile . name } ` ) ;
59- const statusMsg = Gui . setStatusBarMessage ( "Restarted Zowe Remote SSH server" ) ;
60- setTimeout ( ( ) => {
61- statusMsg . dispose ( ) ;
62- // eslint-disable-next-line no-magic-numbers
63- } , 5000 ) ;
64- } ) ,
65- vscode . commands . registerCommand ( `zowe.zowex.uninstall` , async ( profName ?: string ) => {
66- imperative . Logger . getAppLogger ( ) . trace ( "Running uninstall command for profile %s" , profName ) ;
67- const vscePromptApi = new VscePromptApi ( await profCache . getProfileInfo ( ) ) ;
68- const profile = await vscePromptApi . promptForProfile ( profName , { prioritizeProjectLevelConfig : false , disableCreateNewProfile : true } ) ;
69- if ( ! profile ?. profile ) {
70- return ;
71- }
62+ private static async restartCallback ( zoweExplorerApi : IApiExplorerExtender , profName ?: string ) : Promise < void > {
63+ imperative . Logger . getAppLogger ( ) . trace ( "Running restart command for profile %s" , profName ) ;
64+ const profCache = zoweExplorerApi . getProfilesCache ( ) ;
65+ const vscePromptApi = new VscePromptApi ( await profCache . getProfileInfo ( ) ) ;
66+ const profile = await vscePromptApi . promptForProfile ( profName , { prioritizeProjectLevelConfig : false , disableCreateNewProfile : true } ) ;
67+ if ( ! profile ?. profile ) {
68+ return ;
69+ }
7270
73- SshClientCache . inst . end ( profile ) ;
74- const serverPath = ConfigUtils . getServerPath ( profile . profile ) ;
75- await ConfigUtils . showSessionInTree ( profile . name ! , false , zoweExplorerApi ) ;
71+ await SshClientCache . inst . connect ( profile , { restart : true , retryRequests : false } ) ;
7672
77- // Create error callback for uninstall operation
78- const errorCallback = SshErrorHandler . getInstance ( ) . createErrorCallback ( ZoweExplorerApiType . All , "Server uninstall" ) ;
79- await ZSshUtils . uninstallServer ( ZSshUtils . buildSession ( profile . profile ) , serverPath , {
80- onError : errorCallback ,
81- } ) ;
73+ imperative . Logger . getAppLogger ( ) . info ( `Restarted Zowe Remote SSH server on ${ ( profile . profile ?. host as string ) ?? profile . name } ` ) ;
74+ const statusMsg = Gui . setStatusBarMessage ( "Restarted Zowe Remote SSH server" ) ;
75+ setTimeout ( ( ) => {
76+ statusMsg . dispose ( ) ;
77+ // eslint-disable-next-line no-magic-numbers
78+ } , 5000 ) ;
79+ }
8280
83- const infoMsg = `Uninstalled Zowe Remote SSH server from ${ ( profile . profile . host as string ) ?? profile . name } ` ;
84- imperative . Logger . getAppLogger ( ) . info ( infoMsg ) ;
85- await Gui . showMessage ( infoMsg ) ;
86- } ) ,
87- ] ;
81+ private static async uninstallCallback ( zoweExplorerApi : IApiExplorerExtender , profName ?: string ) : Promise < void > {
82+ imperative . Logger . getAppLogger ( ) . trace ( "Running uninstall command for profile %s" , profName ) ;
83+ const profCache = zoweExplorerApi . getProfilesCache ( ) ;
84+ const vscePromptApi = new VscePromptApi ( await profCache . getProfileInfo ( ) ) ;
85+ const profile = await vscePromptApi . promptForProfile ( profName , { prioritizeProjectLevelConfig : false , disableCreateNewProfile : true } ) ;
86+ if ( ! profile ?. profile ) {
87+ return ;
88+ }
89+
90+ SshClientCache . inst . end ( profile ) ;
91+ const serverPath = ConfigUtils . getServerPath ( profile . profile ) ;
92+ await ConfigUtils . showSessionInTree ( profile . name ! , false , zoweExplorerApi ) ;
93+
94+ // Create error callback for uninstall operation
95+ const errorCallback = SshErrorHandler . getInstance ( ) . createErrorCallback ( ZoweExplorerApiType . All , "Server uninstall" ) ;
96+ await ZSshUtils . uninstallServer ( ZSshUtils . buildSession ( profile . profile ) , serverPath , {
97+ onError : errorCallback ,
98+ } ) ;
99+
100+ const infoMsg = `Uninstalled Zowe Remote SSH server from ${ ( profile . profile . host as string ) ?? profile . name } ` ;
101+ imperative . Logger . getAppLogger ( ) . info ( infoMsg ) ;
102+ await Gui . showMessage ( infoMsg ) ;
103+ }
88104}
0 commit comments