-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ed877f8
commit e19c0ce
Showing
12 changed files
with
96 additions
and
73 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
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
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,35 @@ | ||
import { Option } from "@commander-js/extra-typings"; | ||
import path from "path"; | ||
|
||
/** | ||
* The `chdir` cli-option for allowing users to switch their working | ||
* directory. | ||
*/ | ||
export const chdirOption = new Option( | ||
"-c, --chdir <path>", | ||
"change the working directory" | ||
) | ||
.default(null) | ||
.makeOptionMandatory(true); | ||
|
||
/** | ||
* Parsed cli options which include a changed working directory. | ||
*/ | ||
export type ChdirOptions = { | ||
/** | ||
* Overriden working-directory. | ||
*/ | ||
chdir: string | null; | ||
}; | ||
|
||
/** | ||
* Determines the directory in which to execute commands. | ||
* @param processCwd The process cwd. | ||
* @param options Cmd options. | ||
*/ | ||
export function determineCwd( | ||
processCwd: string, | ||
options: ChdirOptions | ||
): string { | ||
return options.chdir !== null ? path.resolve(options.chdir) : processCwd; | ||
} |
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,22 @@ | ||
import path from "path"; | ||
import { determineCwd } from "../../../src/cli/opt-chdir"; | ||
|
||
describe("chdir option", () => { | ||
const testRootPath = "/users/some-user/projects/MyUnityProject"; | ||
|
||
it("should be process directory by default", () => { | ||
const actual = determineCwd(testRootPath, { chdir: null }); | ||
|
||
expect(actual).toEqual(testRootPath); | ||
}); | ||
|
||
it("should be specified path if overridden", () => { | ||
const expected = path.resolve("/some/other/path"); | ||
|
||
const actual = determineCwd(testRootPath, { | ||
chdir: expected, | ||
}); | ||
|
||
expect(actual).toEqual(expected); | ||
}); | ||
}); |
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