Skip to content

Commit

Permalink
fix(cli): configure provider/env correctly in garden plugins command
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and eysi09 committed Mar 18, 2020
1 parent 600e6ac commit 41aacb2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
19 changes: 15 additions & 4 deletions garden-service/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,18 @@ class DummyGarden extends Garden {
}

export async function makeDummyGarden(root: string, gardenOpts: GardenOpts = {}) {
const environments = gardenOpts.environmentName
? [{ name: gardenOpts.environmentName, variables: {} }]
: defaultEnvironments

const config: ProjectConfig = {
path: root,
apiVersion: DEFAULT_API_VERSION,
kind: "Project",
name: "no-project",
defaultEnvironment: "",
dotIgnoreFiles: defaultDotIgnoreFiles,
environments: defaultEnvironments,
environments,
providers: [],
variables: {},
}
Expand Down Expand Up @@ -272,7 +276,14 @@ export class GardenCli {
const parsedArgs = { _: argv._, ...filterByKeys(argv, argKeys) }
const parsedOpts = filterByKeys(argv, optKeys.concat(globalKeys))
const root = resolve(process.cwd(), parsedOpts.root)
const { "logger-type": loggerTypeOpt, "log-level": logLevel, emoji, env, silent, output } = parsedOpts
const {
"logger-type": loggerTypeOpt,
"log-level": logLevel,
emoji,
"env": environmentName,
silent,
output,
} = parsedOpts

let loggerType = loggerTypeOpt || command.loggerType || DEFAULT_CLI_LOGGER_TYPE

Expand All @@ -297,7 +308,7 @@ export class GardenCli {
args: parsedArgs,
opts: parsedOpts,
},
environmentName: env,
environmentName,
log,
}

Expand All @@ -317,7 +328,7 @@ export class GardenCli {
do {
try {
if (command.noProject) {
garden = await makeDummyGarden(root, { ...contextOpts, environmentName: undefined })
garden = await makeDummyGarden(root, contextOpts)
} else {
garden = await Garden.factory(root, contextOpts)
}
Expand Down
16 changes: 8 additions & 8 deletions garden-service/test/unit/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,24 +34,24 @@ describe("cli", () => {
expect(result).to.eql({ args: { _: ["some", "args"] } })
})

it(`ignore the env flag when a command has noProject=true`, async () => {
class TestCommand extends Command {
name = "test-command"
it(`should configure a dummy environment when command has noProject=true and --env is specified`, async () => {
class TestCommand2 extends Command {
name = "test-command-2"
help = "halp!"
noProject = true

async action({ args }) {
return { result: { args } }
async action({ garden }) {
return { result: { environmentName: garden.environmentName } }
}
}

const command = new TestCommand()
const command = new TestCommand2()
const cli = new GardenCli()
cli.addCommand(command, cli["program"])

const { result, errors } = await cli.parse(["test-command", "--env", "invalid-env"])
const { result, errors } = await cli.parse(["test-command-2", "--env", "missing-env"])
expect(errors).to.eql([])
expect(result).to.eql({ args: { _: [] } })
expect(result).to.eql({ environmentName: "missing-env" })
})
})

Expand Down

0 comments on commit 41aacb2

Please sign in to comment.