mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-28 01:25:39 -05:00
Run ADS Commands from Notebooks (#11069)
* Run commands * cleanup * Plumbed through error and message output * undo unnecessary changes * Remove change to fix tests * pr feedback
This commit is contained in:
@@ -13,3 +13,37 @@ export function tryMatchCellMagic(input: string): string {
|
||||
let magicName = match && match[1];
|
||||
return magicName;
|
||||
}
|
||||
|
||||
/**
|
||||
* When a cell is formatted in the following way, extract the commandId and args:
|
||||
* %%ads_execute_command commandId arg1 arg2
|
||||
* Extract the commandId and the two args
|
||||
* @param input cell source
|
||||
* @param magicName magic name
|
||||
*/
|
||||
export function extractCellMagicCommandPlusArgs(input: string, magicName: string): ICommandPlusArgs | undefined {
|
||||
if (input && magicName && input.startsWith(`%%${magicName}`)) {
|
||||
let commandNamePlusArgs = input.replace(`%%${magicName}`, '');
|
||||
if (commandNamePlusArgs?.startsWith(' ')) {
|
||||
// There needs to be a space between the magic name and the command id
|
||||
commandNamePlusArgs = commandNamePlusArgs.slice(1);
|
||||
let commandName = commandNamePlusArgs.split(' ')[0];
|
||||
if (commandName) {
|
||||
let args = commandNamePlusArgs.replace(commandName, '');
|
||||
if (args?.startsWith(' ')) {
|
||||
args = args.slice(1);
|
||||
}
|
||||
return {
|
||||
commandId: commandName,
|
||||
args: args
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export interface ICommandPlusArgs {
|
||||
commandId: string;
|
||||
args: string;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user