UNPKG

@northflank/cli

Version:

Provides a command-line interface to the Northflank platform.

1 lines 10.6 kB
'use strict';const a5p=a5B;(function(I,B){const O=a5B,J=I();while(!![]){try{const C=parseInt(O(0xad))/0x1*(-parseInt(O(0x9b))/0x2)+-parseInt(O(0xb8))/0x3+-parseInt(O(0xee))/0x4*(parseInt(O(0xf4))/0x5)+-parseInt(O(0x93))/0x6*(-parseInt(O(0xd5))/0x7)+-parseInt(O(0xd6))/0x8*(parseInt(O(0x100))/0x9)+parseInt(O(0xae))/0xa*(-parseInt(O(0xdb))/0xb)+parseInt(O(0xc0))/0xc*(parseInt(O(0xcc))/0xd);if(C===B)break;else J['push'](J['shift']());}catch(G){J['push'](J['shift']());}}}(a5I,0xca3de));function a5B(I,B){const J=a5I();return a5B=function(C,G){C=C-0x8c;let F=J[C];return F;},a5B(I,B);}var __awaiter=this&&this[a5p(0xe4)]||function(I,B,J,C){function G(F){return F instanceof J?F:new J(function(A){A(F);});}return new(J||(J=Promise))(function(F,A){const Q=a5B;function H(X){const w=a5B;try{d(C[w(0x106)](X));}catch(S){A(S);}}function t(X){const Z=a5B;try{d(C[Z(0xc9)](X));}catch(S){A(S);}}function d(X){const z=a5B;X[z(0x108)]?F(X[z(0xdd)]):G(X[z(0xdd)])[z(0xf0)](H,t);}d((C=C['apply'](I,B||[]))[Q(0x106)]());});},__importDefault=this&&this['__importDefault']||function(I){return I&&I['__esModule']?I:{'default':I};};Object[a5p(0xba)](exports,a5p(0xc4),{'value':!![]}),exports['CliExec']=void 0x0;const js_client_1=require(a5p(0xeb)),chalk_1=__importDefault(require(a5p(0x8f))),utils_1=require(a5p(0xe7)),inquirer_helper_1=require(a5p(0x9d));function a5I(){const L=['Received\x20Ctrl+D\x20twice,\x20exiting\x20shell\x20forcefully.','askForAddon','getCurrentServiceName','Id\x20[NAME]','2POvovT','70wTojOq','getCommand','getStandardExecCommand','containerName','join','addCommand','execCmd','apiClient','bold','Run\x20command\x20with\x20this\x20user','1209966YmryBd','log','defineProperty','readline','Project\x20for\x20exec','customUserAgent','with\x20user:','default','147336pRTdcb','setRawMode','stdin','CliExec','__esModule','Command\x20completed\x20successfully,\x20exit\x20code:\x20','\x20--cmd\x20\x27date\x27\x0a\x20\x20Single\x20command,\x20custom\x20shell:\x20northflank\x20exec\x20','getTerminalSize',',\x20details:\x20','throw','Container\x20within\x20instance\x20to\x20exec\x20into\x20(if\x20not\x20specified,\x20first\x20container\x20of\x20the\x20instance\x20will\x20be\x20selected)','\x0a\x20\x20Single\x20command,\x20no\x20shell:\x20\x20\x20\x20\x20northflank\x20exec\x20','4030RgilrZ','\x20--','without\x20shell','stdIn','--noDefaults','pipe','--group\x20[GROUP]','status','filter','2986067nHNPLd','8erRPYy','getCurrentProjectName','exec','\x20--cmd\x20\x27\x22ls\x20-l\x20/usr\x22\x27\x20--shell-cmd\x20\x27bash\x20-c\x27\x0a\x20\x20Shell\x20session,\x20custom\x20shell:\x20\x20northflank\x20exec\x20','message','2223188KjosZb','handleShellSession','value','waitForCommandResult','service','with\x20command\x20\x27','Don\x27t\x20use\x20context\x20default\x20values,\x20explicitly\x20use\x20options\x20or\x20ask.','\x27Ctrl+D\x27','(exit\x20with\x20two\x20quick\x20','__awaiter','\x20in\x20container\x20','Command\x20exec\x20for\x20the\x20specified\x20','../utils','\x20command\x20exec:\x20','error','--instance\x20--instanceName\x20[NAME]','@northflank/js-client','stdErr','.\x0aExamples:\x0a\x20\x20Shell\x20session:\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20\x20northflank\x20exec\x20','212qgucfb','rows','then','Unknown','Run\x20command\x20with\x20shell\x20(e.g.\x20\x27bash\x27,\x27sh\x27).\x0aIf\x20not\x20set\x20and\x20no\x20command\x20is\x20provided,\x20several\x20standard\x20shells\x20will\x20be\x20attempted.\x20If\x20not\x20set\x20and\x20a\x20command\x20is\x20provided,\x20the\x20command\x20will\x20run\x20without\x20shell.','emitKeypressEvents','47805AtxExm','Command\x20didn\x27t\x20complete\x20successfully,\x20status:\x20','stderr','stdOut','InquirerHelper','execJobSession','\x20--shell-cmd\x20\x27sh\x27','job','execStartLog','--shell-cmd\x20[SHELL-CMD]','resizeTerminal','alias','5685480rDeBTk','shell\x20command\x20','name','(random\x20instance\x20will\x20be\x20chosen\x20if\x20not\x20specified)','--cmd\x20--command\x20[COMMAND]','Command\x20execution\x20(exec)\x20for\x20Northflank\x20services\x20and\x20jobs.','next','instanceName','done','option','command-exec','Exec\x20','(required)\x20','chalk','action','exit','Command\x20to\x20execute.\x0aIf\x20--shell-cmd\x20option\x20such\x20as\x20\x27bash\x20-c\x27\x20is\x20present,\x20it\x20will\x20run\x20in\x20the\x20specified\x20shell.\x20Otherwise\x20the\x20command\x20will\x20run\x20without\x20a\x20shell.\x20If\x20no\x20command\x20is\x20provided,\x20an\x20interactive\x20session\x20with\x20stdin\x20and\x20tty\x20is\x20opened.','6vmtrDB','\x20on\x20instance\x20','columns','description','keypress','assertContextExisting','Error\x20occured\x20during\x20','execAddonSession','447848YyLPow','greenBright','../inquirer-helper','stdout','askForJob','resize','--project\x20--projectId\x20[NAME]','with\x20shell\x20session','\x20in\x20project\x20','none','sequence','addon','warning','charAt'];a5I=function(){return L;};return a5I();}class CliExec{constructor(I,B){const c=a5p;this[c(0xb0)]=A=>{const l=c,H=(0x0,utils_1[l(0xaf)])(!![])['name'](A)[l(0x96)](l(0xe6)+A+(A==='addon'?'(only\x20applicable\x20for\x20custom\x20addon\x20types)\x20':'')+l(0xed)+A+l(0xcb)+A+l(0xc6)+A+l(0xd9)+A+l(0xfa))['option'](l(0xa1),l(0xbc))[l(0x109)]('--'+A+l(0xcd)+A+l(0xac),A[l(0xa8)](0x0)['toUpperCase']()+A['slice'](0x1)+'\x20to\x20exec\x20into')[l(0x109)](l(0xea),'Instance\x20to\x20exec\x20into\x20'+(A==='addon'?l(0x8e):l(0x103)))[l(0x109)](l(0xfd),l(0xf2))[l(0x109)](l(0xd0),l(0xe1),![])[l(0x109)](l(0x104),l(0x92));return A!==l(0xa6)&&H[l(0x109)]('--user\x20[USER]',l(0xb7))['option'](l(0xd2),'Run\x20command\x20with\x20this\x20group'),A===l(0xa6)&&H[l(0x109)]('--container\x20--containerName\x20[NAME]',l(0xca)),H;},this[c(0xc7)]=()=>({'columns':process[c(0x9e)][c(0x95)],'rows':process[c(0x9e)][c(0xef)]}),this[c(0xfc)]=(A,H,t,d,X,S,f,v,a,V)=>{const n=c;if(v===!![])return;const r=d===n(0xa4),s=a!==undefined?n(0x94)+chalk_1[n(0xbf)]['bold'](a):'',K=V!==undefined?n(0xe5)+chalk_1[n(0xbf)][n(0xb6)](V):'',b=r?n(0xce):d===undefined?n(0xa2):n(0x101)+chalk_1[n(0xbf)][n(0x9c)](d),W=X?n(0xbe)+X:'',u=S?'with\x20group:'+S:'',h=f?n(0xe0)+chalk_1[n(0xbf)]['greenBright'](f)+'\x27':'',q=[h,b,W,u][n(0xd4)](g=>g!=='')[n(0xb2)]('\x20'),x=n(0xe3)+chalk_1['default'][n(0xb6)](n(0xe2))+')';console[n(0xb9)](n(0x8d)+A+'\x20'+chalk_1[n(0xbf)]['bold'](H)+n(0xa3)+chalk_1[n(0xbf)]['bold'](t)+s+K+'\x20'+q+'\x20'+x);},this[c(0xdc)]=(A,H,...t)=>__awaiter(this,[A,H,...t],void 0x0,function*(d,X,S=![]){const m=c;var f,v;let a=![];try{if(process[m(0xc2)]['isTTY']){const r=require(m(0xbb));r[m(0xf3)](process[m(0xc2)]),process[m(0xc2)][m(0xc1)](!![]),process['stdout']['on'](m(0xa0),()=>{const E=m;d[E(0xfe)](this['getTerminalSize']());}),process['stdin']['on'](m(0x97),(s,K)=>{const j=m;K[j(0xa5)]==='\x04'&&(a?(process[j(0xc2)][j(0xc1)](![]),(0x0,utils_1[j(0xa7)])(j(0xa9)),process[j(0x91)]()):(a=!![],setTimeout(()=>a=![],0x190)));});}process[m(0xc2)][m(0xd1)](d[m(0xcf)]),d[m(0xec)][m(0xd1)](process[m(0xf6)]),d[m(0xf7)][m(0xd1)](process[m(0x9e)]),d['on'](m(0xe9),s=>{const U=m;var K;(0x0,utils_1[U(0xe9)])(U(0x99)+X+U(0xe8)+((K=s[U(0xda)])!==null&&K!==void 0x0?K:s)),process[U(0xc2)]['isTTY']&&process[U(0xc2)][U(0xc1)](![]),process[U(0x91)](-0x1);});const V=yield d[m(0xde)]();if(S!==!![]){const s=(f=V===null||V===void 0x0?void 0x0:V[m(0xd3)])!==null&&f!==void 0x0?f:m(0xf1),K=(v=V===null||V===void 0x0?void 0x0:V['exitCode'])!==null&&v!==void 0x0?v:-0x1,b=(V===null||V===void 0x0?void 0x0:V[m(0xda)])?m(0xc8)+V[m(0xda)]:'';s==='Success'?(0x0,utils_1['success'])(m(0xc5)+K):(0x0,utils_1[m(0xa7)])(m(0xf5)+s+',\x20exit\x20code:\x20'+K+b);}return V;}finally{process[m(0xc2)]['isTTY']&&process[m(0xc2)][m(0xc1)](![]);}}),this[c(0xb5)]=new js_client_1['ApiClient'](I,{'throwErrorOnHttpErrorCode':!![],'customUserAgent':utils_1[c(0xbd)],'agent':B});const J=new inquirer_helper_1[(c(0xf8))](this[c(0xb5)]);this[c(0xb4)]=(0x0,utils_1[c(0xaf)])()[c(0x102)](c(0x8c))[c(0xff)](c(0xd8))[c(0x96)](c(0x105));const C=this[c(0xb0)](c(0xdf))['action'](A=>__awaiter(this,void 0x0,void 0x0,function*(){const D=c,{noDefaults:H,projectId:t,serviceId:d,instanceName:X}=A,{shellCmd:S,user:f,group:v,command:a,quiet:V}=A;(0x0,utils_1[D(0x98)])(this[D(0xb5)]);try{const r=H?undefined:I[D(0xd7)](),s=t||r||(yield J['askForProject']()),K=H?undefined:I[D(0xab)](),b=d||K||(yield J['askForService'](s)()),W=S!==null&&S!==void 0x0?S:a!==undefined?'none':undefined,u=process[D(0x9e)][D(0x95)],h=process[D(0x9e)][D(0xef)],q={'projectId':s,'serviceId':b},x={'instanceName':X,'command':a,'shell':W,'user':f,'group':v,'ttyColumns':u,'ttyRows':h},g=yield this[D(0xb5)][D(0xd8)]['execServiceSession'](q,x,o=>{const M=D;this[M(0xfc)](M(0xdf),b,s,S,f,v,a,V,o[M(0x107)],o[M(0xb1)]);});yield this[D(0xdc)](g,D(0xdf),V);}catch(o){(0x0,utils_1[D(0xe9)])(''+o[D(0xda)]);}finally{process['exit']();}})),G=this[c(0xb0)](c(0xfb))[c(0x90)](A=>__awaiter(this,void 0x0,void 0x0,function*(){const R=c,{projectId:H,jobId:t,instanceName:d}=A,{noDefaults:X,shellCmd:S,user:f,group:v,command:a,quiet:V}=A;(0x0,utils_1[R(0x98)])(this[R(0xb5)]);try{const r=X?undefined:I['getCurrentProjectName'](),s=H||r||(yield J['askForProject']()),K=t||(yield J[R(0x9f)](s)()),{rows:b,columns:W}=this['getTerminalSize'](),u={'projectId':s,'jobId':K},h={'instanceName':d,'command':a,'shell':S,'user':f,'group':v,'ttyColumns':W,'ttyRows':b},q=yield this[R(0xb5)][R(0xd8)][R(0xf9)](u,h,x=>{const Y=R;this[Y(0xfc)](Y(0xfb),K,s,S,f,v,a,V,x[Y(0x107)],x['containerName']);});yield this[R(0xdc)](q,R(0xfb),V);}catch(x){(0x0,utils_1[R(0xe9)])(''+x[R(0xda)]);}finally{process['exit']();}})),F=this['getStandardExecCommand'](c(0xa6))[c(0x90)](A=>__awaiter(this,void 0x0,void 0x0,function*(){const P=c,{projectId:H,addonId:t,instanceName:d,containerName:X}=A,{noDefaults:S,shellCmd:f,user:v,group:a,command:V,quiet:r}=A;(0x0,utils_1[P(0x98)])(this[P(0xb5)]);try{const s=S?undefined:I['getCurrentProjectName'](),K=H||s||(yield J['askForProject']()),b=t||(yield J[P(0xaa)](K)()),{rows:W,columns:u}=this[P(0xc7)](),h=f!==null&&f!==void 0x0?f:V!==undefined?P(0xa4):undefined,q={'projectId':K,'addonId':b},x={'instanceName':d,'containerName':X,'command':V,'shell':h,'user':v,'group':a,'ttyColumns':u,'ttyRows':W},g=yield this[P(0xb5)]['exec'][P(0x9a)](q,x,o=>{const k=P;this[k(0xfc)]('addon',b,K,h,v,a,V,r,o['instanceName'],o['containerName']);});yield this['handleShellSession'](g,P(0xa6),r);}catch(o){(0x0,utils_1['error'])(''+o[P(0xda)]);}finally{process[P(0x91)]();}}));this['execCmd'][c(0xb3)](C),this[c(0xb4)][c(0xb3)](G),this[c(0xb4)]['addCommand'](F);}}exports[a5p(0xc3)]=CliExec;