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

feat: inso global env id #8039

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all 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
18 changes: 10 additions & 8 deletions packages/insomnia-inso/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ export const go = (args?: string[]) => {
You can also point it at a git repository folder, or an Insomnia export file.

Examples:
$ inso run collection
$ inso run test
$ inso lint spec
$ inso export spec
Expand All @@ -329,13 +330,10 @@ export const go = (args?: string[]) => {
Inso also supports configuration files, by default it will look for .insorc in the current/provided working directory.
$ inso export spec --config /some/path/.insorc
`)
// TODO: make fallback dir clearer
.option('-w, --workingDir <dir>', 'set working directory, to look for files: .insorc, .insomnia folder, *.db.json', '')
// TODO: figure out how to remove this option
.option('--exportFile <file>', 'set the Insomna export file read from', '')
.option('-w, --workingDir <dir>', 'set working directory/file: .insomnia folder, *.db.json, export.yaml', '')
.option('--verbose', 'show additional logs while running the command', false)
.option('--ci', 'run in CI, disables all prompts, defaults to false', false)
.option('--config <path>', 'path to configuration file containing above options', '')
.option('--config <path>', 'path to configuration file containing above options (.insorc)', '')
.option('--printOptions', 'print the loaded options', false);

const run = program.command('run')
Expand Down Expand Up @@ -431,14 +429,15 @@ export const go = (args?: string[]) => {
.option('-t, --requestNamePattern <regex>', 'run requests that match the regex', '')
.option('-i, --item <requestid>', 'request or folder id to run', collect, [])
.option('-e, --env <identifier>', 'environment to use', '')
.option('-g, --globals <identifier>', 'global environment to use', '')
.option('--delay-request <duration>', 'milliseconds to delay between requests', '0')
.option('--env-var <key=value>', 'override environment variables', collect, [])
.option('-n, --iteration-count <count>', 'number of times to repeat', '1')
.option('-d, --iteration-data <path/url>', 'file path or url (JSON or CSV)', '')
.option('-r, --reporter <reporter>', `reporter to use, options are [${reporterTypes.join(', ')}]`, defaultReporter)
.option('-b, --bail', 'abort ("bail") after first non-200 response', false)
.option('--disableCertValidation', 'disable certificate validation for requests with SSL', false)
.action(async (identifier, cmd: { env: string; disableCertValidation: boolean; requestNamePattern: string; bail: boolean; item: string[]; delayRequest: string; iterationCount: string; iterationData: string; envVar: string[] }) => {
.action(async (identifier, cmd: { env: string; globals: string; disableCertValidation: boolean; requestNamePattern: string; bail: boolean; item: string[]; delayRequest: string; iterationCount: string; iterationData: string; envVar: string[] }) => {
const globals: { config: string; workingDir: string; exportFile: string; ci: boolean; printOptions: boolean; verbose: boolean } = program.optsWithGlobals();

const commandOptions = { ...globals, ...cmd };
Expand Down Expand Up @@ -485,8 +484,11 @@ export const go = (args?: string[]) => {

// Find environment
const workspaceId = workspace._id;
const environment = options.env ? loadEnvironment(db, workspaceId, options.env) : await promptEnvironment(db, !!options.ci, workspaceId);

const globalEnvironment = options.globals ? loadEnvironment(db, workspaceId, options.globals) : null;
let environment = options.env ? loadEnvironment(db, workspaceId, options.env) : await promptEnvironment(db, !!options.ci, workspaceId);
if (globalEnvironment) {
environment = { ...globalEnvironment, ...environment };
}
if (!environment) {
logger.fatal('No environment identified; cannot run requests without a valid environment.');
return process.exit(1);
Expand Down
Loading