@@ -27,6 +27,7 @@ import {
2727 Range ,
2828 Position ,
2929 languages ,
30+ ThemeIcon ,
3031} from 'vscode' ;
3132import jsYaml from 'js-yaml' ;
3233import * as path from 'path' ;
@@ -64,6 +65,7 @@ import { Telemetry } from './telemetry';
6465import { XcDiag } from './tmosXcDiag' ;
6566import { NextApi } from './nextApi' ;
6667import { CodeLensProvider } from './codeLens' ;
68+ import { createRequire } from 'module' ;
6769
6870// turn off console logging
6971logger . console = false ;
@@ -78,7 +80,7 @@ logger.output = function (log: string) {
7880
7981
8082// provide extension functions for activation
81- export async function activateInternal ( context : ExtensionContext ) {
83+ export async function activate ( context : ExtensionContext ) {
8284
8385 process . on ( 'unhandledRejection' , error => {
8486 logger . error ( '--- unhandledRejection ---' , error ) ;
@@ -141,7 +143,7 @@ export async function activateInternal(context: ExtensionContext) {
141143
142144 new CfCore ( context ) ;
143145
144- new NextApi ( context , ext . eventEmitterGlobal ) ;
146+ // new NextApi(context, ext.eventEmitterGlobal);
145147
146148 languages . registerCodeLensProvider ( {
147149 language : 'json' ,
@@ -932,32 +934,132 @@ export async function activateInternal(context: ExtensionContext) {
932934
933935 ext . telemetry . capture ( { command : 'f5.remoteCommand' } ) ;
934936
935- // todo: add a setting to hold the command and future history
936- await window . showQuickPick (
937- [
938- 'cat /config/bigip.conf' ,
939- 'cat bigip.license' ,
940- 'tail -100 /var/log/ltm' ,
941- 'tmsh show /apm license'
942- ] , {
943- ignoreFocusOut : true ,
944- title : 'Enter command to execute on the BIG-IP'
945- } )
946- . then ( async cmd => {
947-
948- if ( cmd ) {
949-
950- await ext . f5Client ?. https ( `/mgmt/tm/util/bash` , {
951- method : 'POST' ,
952- data : {
953- command : 'run' ,
954- utilCmdArgs : `-c '${ cmd } '`
955- }
956- } )
957- . then ( resp => ext . panel . render ( resp . data . commandResult ) )
958- . catch ( err => logger . error ( 'bash command failed:' , err ) ) ;
937+ // get the cmd history from vscode global state
938+ const histary : string [ ] = context . globalState . get ( 'f5-rc-history' , [ ] ) ;
939+
940+ const historyDefaults = [
941+ 'cat /config/bigip.conf' ,
942+ 'cat bigip.license' ,
943+ 'tail -100 /var/log/ltm' ,
944+ 'tmsh show /apm license'
945+ ] ;
946+
947+ const cmd = await new Promise ( ( resolve ) => {
948+
949+ const qp = window . createQuickPick ( )
950+
951+ //build all the history items with delete buttons
952+ const i = histary . map ( label => ( {
953+ label,
954+ buttons : [ { iconPath : new ThemeIcon ( "trash" ) , tooltip : "Remove this item" } ]
955+ } ) )
956+
957+ // build all the defaults (no delete button)
958+ const ii = historyDefaults . map ( label => ( { label } ) )
959+
960+ // spread all the options together
961+ qp . items = [ ...i , ...ii ] ;
962+
963+ // allow focus out
964+ qp . ignoreFocusOut = true ;
965+
966+ // event for history button (trash)
967+ qp . onDidTriggerItemButton ( async ( _button ) => {
968+
969+ // isolat the value
970+ const item = _button . item . label ;
971+
972+ // filter out this button item from the history array
973+ const newHistary = histary . filter ( x => x !== item )
974+ // clear the history array
975+ histary . length = 0
976+ // spread all the filtered records back into the history array
977+ histary . push ( ...newHistary )
978+
979+ // rerun the command to get new values
980+ return commands . executeCommand ( 'f5.remoteCommand' )
981+
982+ } ) ,
983+
984+ qp . onDidAccept ( a => {
985+
986+ // main quick pick object
987+ const b = qp ;
988+ // if new item typed in
989+ const bv = b . value ;
990+ // if existing item selected;
991+ const bs = b . selectedItems [ 0 ] ?. label ;
992+
993+ resolve ( bv || bs ) ;
994+ qp . hide ( ) ;
995+ } )
996+
997+ qp . show ( ) ;
998+ } ) as string ;
999+
1000+ if ( cmd ) {
1001+
1002+ // console.log(cmd)
1003+
1004+ await ext . f5Client ?. https ( `/mgmt/tm/util/bash` , {
1005+ method : 'POST' ,
1006+ data : {
1007+ command : 'run' ,
1008+ utilCmdArgs : `-c '${ cmd } '`
9591009 }
960- } ) ;
1010+ } )
1011+ . then ( resp => {
1012+
1013+ // render the output for the user
1014+ ext . panel . render ( resp . data . commandResult )
1015+
1016+ // is command part of the historyDefaults
1017+ const isDefaultCmd = historyDefaults . indexOf ( cmd ) ;
1018+
1019+ if ( isDefaultCmd < 0 ) {
1020+
1021+ //is command already in the history
1022+ const idx = histary . indexOf ( cmd )
1023+
1024+ // command is not in history
1025+ if ( idx < 0 ) {
1026+
1027+ // add the cmd to the top of the history array
1028+ histary . unshift ( cmd )
1029+
1030+ } else {
1031+
1032+ // command found in history
1033+ // remove command by index
1034+ histary . splice ( idx , 1 )
1035+ // re-add command back to the top
1036+ histary . unshift ( cmd )
1037+ }
1038+
1039+ // if we exceed 5, remove oldest
1040+ if ( histary . length > 5 ) histary . pop ( ) ;
1041+
1042+ // save the array to the vscode global state
1043+ context . globalState . update ( 'f5-rc-history' , histary )
1044+ }
1045+
1046+ } )
1047+ . catch ( err => logger . error ( 'bash command failed:' , err ) ) ;
1048+ }
1049+
1050+
1051+ // }
1052+
1053+
1054+
1055+ // // merge the history and defaults to disply for user, with latest history on top
1056+ // await window.showQuickPick([...histary, ...historyDefaults], {
1057+ // ignoreFocusOut: true,
1058+ // title: 'Enter command to execute on the BIG-IP'
1059+ // })
1060+ // .then(async cmd => {
1061+
1062+
9611063
9621064 } ) ) ;
9631065
@@ -969,6 +1071,6 @@ export async function activateInternal(context: ExtensionContext) {
9691071
9701072
9711073// this method is called when your extension is deactivated
972- export async function deactivateInternal ( context : ExtensionContext ) {
1074+ export async function deactivate ( context : ExtensionContext ) {
9731075 // log deactivation event
9741076}
0 commit comments