-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI command to directly execute a Sol command
- Loading branch information
Showing
3 changed files
with
34 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { Command } from 'commander'; | ||
import * as vm from 'vm'; | ||
|
||
export function execCommand(): Command { | ||
return new Command('exec') | ||
.description('Executed the given command') | ||
.argument( | ||
'<command>', | ||
'Command to run (e.g. `text("test").uppercased` to uppercase "test")', | ||
) | ||
.action(async (command: string) => { | ||
// Use VM to execute command in a sandbox | ||
const output = vm.runInThisContext(command); | ||
|
||
// Write output to stdout | ||
log(output); | ||
}); | ||
} |