-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Reorganize CLI commands for better readability
- Loading branch information
Showing
10 changed files
with
492 additions
and
340 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { Command } from "commander"; | ||
|
||
import { | ||
bundleFileOption, | ||
bundleFileOptionValue, | ||
sourcesFolderOption, | ||
sourcesFolderOptionValue, | ||
typescriptOption, | ||
typescriptOptionValueWithDefaults | ||
} from "./options"; | ||
import { findSimulations } from "../simulations"; | ||
import { bundle } from "../bundle"; | ||
|
||
export default (program: Command): void => { | ||
program | ||
.command("build") | ||
.description("Build Gatling simulations") | ||
.addOption(sourcesFolderOption) | ||
.addOption(bundleFileOption) | ||
.addOption(typescriptOption) | ||
.action(async (options) => { | ||
const sourcesFolder: string = sourcesFolderOptionValue(options); | ||
const bundleFile = bundleFileOptionValue(options); | ||
|
||
const simulations = await findSimulations(sourcesFolder); | ||
const typescript = typescriptOptionValueWithDefaults(options, simulations); | ||
|
||
await bundle({ sourcesFolder, bundleFile, typescript, simulations }); | ||
}); | ||
}; |
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,88 @@ | ||
import { Command } from "commander"; | ||
|
||
import { | ||
apiTokenOption, | ||
apiTokenOptionValue, | ||
bundleFileOption, | ||
bundleFileOptionValue, | ||
controlPlaneUrlOption, | ||
controlPlaneUrlOptionValue, | ||
gatlingHomeOption, | ||
gatlingHomeOptionValueWithDefaults, | ||
nonInteractiveOption, | ||
nonInteractiveOptionValue, | ||
packageDescriptorFilenameOption, | ||
packageDescriptorFilenameOptionValue, | ||
packageFileOption, | ||
packageFileOptionValue, | ||
resourcesFolderOption, | ||
resourcesFolderOptionValue, | ||
resultsFolderOption, | ||
resultsFolderOptionValue, | ||
sourcesFolderOption, | ||
sourcesFolderOptionValue, | ||
typescriptOption, | ||
typescriptOptionValueWithDefaults, | ||
urlOption, | ||
urlOptionValue | ||
} from "./options"; | ||
import { findSimulations } from "../simulations"; | ||
import { installGatlingJs } from "../dependencies"; | ||
import { bundle } from "../bundle"; | ||
import { enterpriseDeploy, enterprisePackage } from "../enterprise"; | ||
|
||
export default (program: Command): void => { | ||
program | ||
.command("enterprise-deploy") | ||
.description("Deploy a package and configured simulations") | ||
.addOption(sourcesFolderOption) | ||
.addOption(resourcesFolderOption) | ||
.addOption(bundleFileOption) | ||
.addOption(resultsFolderOption) | ||
.addOption(typescriptOption) | ||
.addOption(gatlingHomeOption) | ||
// Base | ||
.addOption(urlOption) | ||
.addOption(apiTokenOption) | ||
// Plugin configuration | ||
.addOption(controlPlaneUrlOption) | ||
.addOption(nonInteractiveOption) | ||
// Descriptor file | ||
.addOption(packageDescriptorFilenameOption) | ||
// Deployment info | ||
.addOption(packageFileOption) | ||
.action(async (options) => { | ||
const sourcesFolder: string = sourcesFolderOptionValue(options); | ||
|
||
const simulations = await findSimulations(sourcesFolder); | ||
const typescript = typescriptOptionValueWithDefaults(options, simulations); | ||
|
||
const resourcesFolder: string = resourcesFolderOptionValue(options); | ||
const bundleFile = bundleFileOptionValue(options); | ||
const resultsFolder: string = resultsFolderOptionValue(options); | ||
const gatlingHome = gatlingHomeOptionValueWithDefaults(options); | ||
const url = urlOptionValue(options); | ||
const apiToken = apiTokenOptionValue(options); | ||
const controlPlaneUrl = controlPlaneUrlOptionValue(options); | ||
const nonInteractive = nonInteractiveOptionValue(options); | ||
const packageDescriptorFilename = packageDescriptorFilenameOptionValue(options); | ||
const packageFile = packageFileOptionValue(options); | ||
|
||
const { graalvmHome, jvmClasspath } = await installGatlingJs({ gatlingHome }); | ||
await bundle({ sourcesFolder, bundleFile, typescript, simulations }); | ||
await enterprisePackage({ bundleFile, resourcesFolder, packageFile, simulations }); | ||
await enterpriseDeploy({ | ||
graalvmHome, | ||
jvmClasspath, | ||
bundleFile, | ||
resourcesFolder, | ||
resultsFolder, | ||
url, | ||
apiToken, | ||
controlPlaneUrl, | ||
nonInteractive, | ||
packageDescriptorFilename, | ||
packageFile | ||
}); | ||
}); | ||
}; |
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,41 @@ | ||
import { Command } from "commander"; | ||
|
||
import { | ||
bundleFileOption, | ||
bundleFileOptionValue, | ||
packageFileOption, | ||
packageFileOptionValue, | ||
resourcesFolderOption, | ||
resourcesFolderOptionValue, | ||
sourcesFolderOption, | ||
sourcesFolderOptionValue, | ||
typescriptOption, | ||
typescriptOptionValueWithDefaults | ||
} from "./options"; | ||
import { findSimulations } from "../simulations"; | ||
import { bundle } from "../bundle"; | ||
import { enterprisePackage } from "../enterprise"; | ||
|
||
export default (program: Command): void => { | ||
program | ||
.command("enterprise-package") | ||
.description("Build Gatling simulations and package them for Gatling Enterprise") | ||
.addOption(sourcesFolderOption) | ||
.addOption(resourcesFolderOption) | ||
.addOption(bundleFileOption) | ||
.addOption(packageFileOption) | ||
.addOption(typescriptOption) | ||
.action(async (options) => { | ||
const sourcesFolder: string = sourcesFolderOptionValue(options); | ||
const resourcesFolder: string = resourcesFolderOptionValue(options); | ||
const bundleFile = bundleFileOptionValue(options); | ||
const packageFile = packageFileOptionValue(options); | ||
|
||
const simulations = await findSimulations(sourcesFolder); | ||
const typescript = typescriptOptionValueWithDefaults(options, simulations); | ||
|
||
await bundle({ sourcesFolder, bundleFile, typescript, simulations }); | ||
|
||
await enterprisePackage({ bundleFile, resourcesFolder, packageFile, simulations }); | ||
}); | ||
}; |
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,113 @@ | ||
import { Command } from "commander"; | ||
|
||
import { | ||
apiTokenOption, | ||
apiTokenOptionValue, | ||
bundleFileOption, | ||
bundleFileOptionValue, | ||
controlPlaneUrlOption, | ||
controlPlaneUrlOptionValue, | ||
enterpriseSimulationOption, | ||
enterpriseSimulationOptionValue, | ||
gatlingHomeOption, | ||
gatlingHomeOptionValueWithDefaults, | ||
nonInteractiveOption, | ||
nonInteractiveOptionValue, | ||
packageDescriptorFilenameOption, | ||
packageDescriptorFilenameOptionValue, | ||
packageFileOption, | ||
packageFileOptionValue, | ||
resourcesFolderOption, | ||
resourcesFolderOptionValue, | ||
resultsFolderOption, | ||
resultsFolderOptionValue, | ||
runDescriptionOption, | ||
runDescriptionOptionValue, | ||
runTitleOption, | ||
runTitleOptionValue, | ||
sourcesFolderOption, | ||
sourcesFolderOptionValue, | ||
typescriptOption, | ||
typescriptOptionValueWithDefaults, | ||
urlOption, | ||
urlOptionValue, | ||
waitForRunEndOption, | ||
waitForRunEndOptionValue | ||
} from "./options"; | ||
import { findSimulations } from "../simulations"; | ||
import { installGatlingJs } from "../dependencies"; | ||
import { bundle } from "../bundle"; | ||
import { enterprisePackage, enterpriseStart } from "../enterprise"; | ||
|
||
export default (program: Command): void => { | ||
program | ||
.command("enterprise-start") | ||
.description("Start a simulation deployed with `enterprise-deploy`") | ||
.addOption(sourcesFolderOption) | ||
.addOption(resourcesFolderOption) | ||
.addOption(bundleFileOption) | ||
.addOption(resultsFolderOption) | ||
.addOption(typescriptOption) | ||
.addOption(gatlingHomeOption) | ||
// Base | ||
.addOption(urlOption) | ||
.addOption(apiTokenOption) | ||
// Plugin configuration | ||
.addOption(controlPlaneUrlOption) | ||
.addOption(nonInteractiveOption) | ||
// Descriptor file | ||
.addOption(packageDescriptorFilenameOption) | ||
// Deployment info | ||
.addOption(packageFileOption) | ||
// Start | ||
.addOption(enterpriseSimulationOption) | ||
.addOption(runTitleOption) | ||
.addOption(runDescriptionOption) | ||
.addOption(waitForRunEndOption) | ||
.action(async (options) => { | ||
const sourcesFolder: string = sourcesFolderOptionValue(options); | ||
|
||
const simulations = await findSimulations(sourcesFolder); | ||
const typescript = typescriptOptionValueWithDefaults(options, simulations); | ||
|
||
const resourcesFolder: string = resourcesFolderOptionValue(options); | ||
const bundleFile = bundleFileOptionValue(options); | ||
const resultsFolder: string = resultsFolderOptionValue(options); | ||
const gatlingHome = gatlingHomeOptionValueWithDefaults(options); | ||
const url = urlOptionValue(options); | ||
const apiToken = apiTokenOptionValue(options); | ||
const controlPlaneUrl = controlPlaneUrlOptionValue(options); | ||
const nonInteractive = nonInteractiveOptionValue(options); | ||
const packageDescriptorFilename = packageDescriptorFilenameOptionValue(options); | ||
const packageFile = packageFileOptionValue(options); | ||
const enterpriseSimulation = enterpriseSimulationOptionValue(options); | ||
const runTitle = runTitleOptionValue(options); | ||
const runDescription = runDescriptionOptionValue(options); | ||
const waitForRunEnd = waitForRunEndOptionValue(options); | ||
|
||
if (nonInteractiveOptionValue(options) && enterpriseSimulation === undefined) { | ||
throw new Error(`No simulation specified when using non-interactive mode`); | ||
} | ||
|
||
const { graalvmHome, jvmClasspath } = await installGatlingJs({ gatlingHome }); | ||
await bundle({ sourcesFolder, bundleFile, typescript, simulations }); | ||
await enterprisePackage({ bundleFile, resourcesFolder, packageFile, simulations }); | ||
await enterpriseStart({ | ||
graalvmHome, | ||
jvmClasspath, | ||
bundleFile, | ||
resourcesFolder, | ||
resultsFolder, | ||
url, | ||
apiToken, | ||
controlPlaneUrl, | ||
nonInteractive, | ||
packageDescriptorFilename, | ||
packageFile, | ||
enterpriseSimulation, | ||
runTitle, | ||
runDescription, | ||
waitForRunEnd | ||
}); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -1 +1,25 @@ | ||
export * from "./options"; | ||
import { Command } from "commander"; | ||
|
||
import registerInstallCommand from "./install"; | ||
import registerBuildCommand from "./build"; | ||
import registerRunOnlyCommand from "./runOnly"; | ||
import registerRunCommand from "./run"; | ||
import registerRecorderCommand from "./recorder"; | ||
import registerEnterprisePackageCommand from "./enterprisePackage"; | ||
import registerEnterpriseDeployCommand from "./enterpriseDeploy"; | ||
import registerEnterpriseStartCommand from "./enterpriseStart"; | ||
import { versions } from "../dependencies"; | ||
|
||
export const program: Command = new Command() | ||
.name("gatling-js-cli") | ||
.version(versions.gatling.jsAdapter) | ||
.description("The Gatling Javascript run & packaging tool"); | ||
|
||
registerInstallCommand(program); | ||
registerBuildCommand(program); | ||
registerRunOnlyCommand(program); | ||
registerRunCommand(program); | ||
registerRecorderCommand(program); | ||
registerEnterprisePackageCommand(program); | ||
registerEnterpriseDeployCommand(program); | ||
registerEnterpriseStartCommand(program); |
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,19 @@ | ||
import { Command } from "commander"; | ||
|
||
import { gatlingHomeOption, gatlingHomeOptionValueWithDefaults } from "./options"; | ||
import { installGatlingJs } from "../dependencies"; | ||
import { logger } from "../log"; | ||
|
||
export default (program: Command): void => { | ||
program | ||
.command("install") | ||
.description("Install all required components and dependencies for Gatling") | ||
.addOption(gatlingHomeOption) | ||
.action(async (options) => { | ||
const gatlingHome = gatlingHomeOptionValueWithDefaults(options); | ||
const { graalvmHome, coursierBinary, jvmClasspath } = await installGatlingJs({ gatlingHome }); | ||
logger.info(`graalvmHome=${graalvmHome}`); | ||
logger.info(`coursierBinary=${coursierBinary}`); | ||
logger.info(`jvmClasspath=${jvmClasspath}`); | ||
}); | ||
}; |
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,41 @@ | ||
import { Command } from "commander"; | ||
|
||
import { | ||
gatlingHomeOption, | ||
gatlingHomeOptionValueWithDefaults, | ||
resourcesFolderOption, | ||
resourcesFolderOptionValue, | ||
sourcesFolderOption, | ||
sourcesFolderOptionValue, | ||
typescriptOption, | ||
typescriptOptionValueWithDefaults | ||
} from "./options"; | ||
import { findSimulations } from "../simulations"; | ||
import { installRecorder } from "../dependencies"; | ||
import { logger } from "../log"; | ||
import { runRecorder } from "../run"; | ||
|
||
export default (program: Command): void => { | ||
program | ||
.command("recorder") | ||
.description("Run the Gatling recorder") | ||
.addOption(gatlingHomeOption) | ||
.addOption(sourcesFolderOption) | ||
.addOption(typescriptOption) | ||
.addOption(resourcesFolderOption) | ||
.action(async (options) => { | ||
const gatlingHome: string = gatlingHomeOptionValueWithDefaults(options); | ||
const sourcesFolder: string = sourcesFolderOptionValue(options); | ||
const resourcesFolder: string = resourcesFolderOptionValue(options); | ||
|
||
const simulations = await findSimulations(sourcesFolder); | ||
const typescript = typescriptOptionValueWithDefaults(options, simulations); | ||
|
||
const { graalvmHome, coursierBinary, jvmClasspath } = await installRecorder({ gatlingHome }); | ||
logger.debug(`graalvmHome=${graalvmHome}`); | ||
logger.debug(`coursierBinary=${coursierBinary}`); | ||
logger.debug(`jvmClasspath=${jvmClasspath}`); | ||
|
||
await runRecorder({ graalvmHome, jvmClasspath, sourcesFolder, typescript, resourcesFolder }); | ||
}); | ||
}; |
Oops, something went wrong.