Skip to content

Commit

Permalink
fix(cli): ignore --env flag for commands that don't use a project config
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald authored and thsig committed Mar 17, 2020
1 parent 9d520e0 commit ccfd8ff
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 1 deletion.
2 changes: 1 addition & 1 deletion garden-service/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ export class GardenCli {
do {
try {
if (command.noProject) {
garden = await makeDummyGarden(root, contextOpts)
garden = await makeDummyGarden(root, { ...contextOpts, environmentName: undefined })
} else {
garden = await Garden.factory(root, contextOpts)
}
Expand Down
20 changes: 20 additions & 0 deletions garden-service/test/unit/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,26 @@ describe("cli", () => {
const { result } = await cli.parse(["test-command", "some", "args"])
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"
help = "halp!"
noProject = true

async action({ args }) {
return { result: { args } }
}
}

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

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

describe("makeDummyGarden", () => {
Expand Down
16 changes: 16 additions & 0 deletions garden-service/test/unit/src/commands/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,20 @@ describe("PluginsCommand", () => {

expect(result).to.eql({ args: ["foo"] })
})

it(`ignore the env flag when printing help text`, async () => {
const garden = await TestGarden.factory(tmpDir.path, { plugins: [testPluginA, testPluginB] })
const log = garden.log

const result = await command.action({
garden,
log,
headerLog: log,
footerLog: log,
args: { plugin: undefined, command: undefined },
opts: withDefaultGlobalOpts({ env: "invalid-env" }),
})

expect(result.errors).to.be.undefined
})
})

0 comments on commit ccfd8ff

Please sign in to comment.