Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug - running command not in content #60

Merged
merged 8 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Commands:
* You can also run the commands directry from the explorer menu:
![sidebar](documentation/changelog/0.0.3/sidebar.png)

NOTE: You have to run the commands from a content-like repository, i.e. */content/packs/* .
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
NOTE: You have to run the commands from a content-like repository, i.e. */content/packs/* .
NOTE: To use the extension, make sure there's a `Packs` folder at the repository root.


## Configurations

### Local Environment (LINUX or MacOS)
Expand Down
2 changes: 2 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export function activate(context: vscode.ExtensionContext): void {
Logger.createLogger()
const contentPath = tools.getContentPath()
if (!contentPath) {
vscode.window.showErrorMessage('Could not find content path, run the command from a content directory.');
// dont activate outside of content path
return
}
Expand Down Expand Up @@ -70,6 +71,7 @@ export function activate(context: vscode.ExtensionContext): void {

context.subscriptions.push(
vscode.commands.registerCommand('xsoar.run', (file: vscode.Uri | undefined) => {

const fileToRun = getDirPath(file)
runAndDebug.run(fileToRun)
})
Expand Down
16 changes: 16 additions & 0 deletions src/terminalManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ import { Logger } from "./logger";
* Used to manage backgrount terminal. Will auto-kill any terminal that is older than
* 60 seconds.
*/

export function isRunningInsideContent(): boolean {
const contentPath = tools.getContentPath()
if (!contentPath) {
vscode.window.showErrorMessage('Could not find content path, run the command from a content directory.');
return false;
}
return true;
}

export class TerminalManager {
static terminal: vscode.Terminal;
private static delay(ms: number) {
Expand All @@ -22,6 +32,8 @@ export class TerminalManager {
// options: vscode.TerminalOptions,
options: ProcessEnvOptions
): Promise<void> {
if (!isRunningInsideContent())
return;
const sdkPath = tools.getSDKPath()
for (let i = 0; i < command.length; i++) {
if (command[i].includes(' ')) {
Expand All @@ -44,6 +56,8 @@ export class TerminalManager {

public static async sendDemistoSdkCommandWithProgress(command: string[]): Promise<boolean> {
const sdkPath = tools.getSDKPath()
if (!isRunningInsideContent())
return false;
// loop the command and add quotes to each argument
for (let i = 0; i < command.length; i++) {
if (command[i].includes(' ')) {
Expand Down Expand Up @@ -115,6 +129,8 @@ export class TerminalManager {
newTerminal = false,
timeout = 10000
): Promise<void> {
if (!isRunningInsideContent())
return;
for (let i = 0; i < command.length; i++) {
if (command[i].includes(' ')) {
command[i] = `"${command[i]}"`
Expand Down
Loading