Skip to content

Commit

Permalink
feat(versioncmd): add version command
Browse files Browse the repository at this point in the history
  • Loading branch information
drubin committed Jan 10, 2019
1 parent 9a65de2 commit 8be4761
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/BUG_REPORT.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ about: Create a report to help make garden better
<!-- PLEASE FILL THIS OUT -->

<!-- Please run and copy and paste the results -->
`garden -v`
`garden version`

`kubectl version`

Expand Down
9 changes: 9 additions & 0 deletions docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -801,3 +801,12 @@ Throws an error and exits with code 1 if something's not right in your garden.ym

garden validate

### garden version

Show&#x27;s the current cli version.


##### Usage

garden version

4 changes: 3 additions & 1 deletion garden-service/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import {
prepareArgConfig,
prepareOptionConfig,
styleConfig,
getPackageVersion,
} from "./helpers"
import { GardenConfig } from "../config/base"
import { defaultEnvironments } from "../config/project"
Expand Down Expand Up @@ -174,7 +175,7 @@ export class GardenCli {
private fileWritersInitialized: boolean = false

constructor() {
const version = require("../../package.json").version
const version = getPackageVersion()
this.program = sywac
.help("-h, --help", {
group: GLOBAL_OPTIONS_GROUP_NAME,
Expand All @@ -183,6 +184,7 @@ export class GardenCli {
.version("-v, --version", {
version,
group: GLOBAL_OPTIONS_GROUP_NAME,
description: "Show's the current cli version.",
implicitCommand: false,
})
.showHelpByDefault()
Expand Down
5 changes: 5 additions & 0 deletions garden-service/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,8 @@ export function failOnInvalidOptions(argv, ctx) {
ctx.cliMessage(`Received invalid flag(s): ${invalid.join(", ")}`)
}
}

export function getPackageVersion(): String {
const version = require("../../package.json").version
return version
}
2 changes: 2 additions & 0 deletions garden-service/src/commands/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { UpdateRemoteCommand } from "./update-remote/update-remote"
import { ValidateCommand } from "./validate"
import { ExecCommand } from "./exec"
import { ServeCommand } from "./serve"
import { VersionCommand } from "./version"

export const coreCommands: Command[] = [
new BuildCommand(),
Expand All @@ -49,4 +50,5 @@ export const coreCommands: Command[] = [
new UnlinkCommand(),
new UpdateRemoteCommand(),
new ValidateCommand(),
new VersionCommand(),
]
27 changes: 27 additions & 0 deletions garden-service/src/commands/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import {
Command,
CommandResult,
CommandParams,
} from "./base"
import { getPackageVersion } from "../cli/helpers"
import chalk from "chalk"

export class VersionCommand extends Command {
name = "version"
help = "Show's the current cli version."

async action({ log }: CommandParams<{}>): Promise<CommandResult<String>> {
const result = `${getPackageVersion()}`

log.info(`${chalk.white(result)}`)
return { result }
}
}
19 changes: 19 additions & 0 deletions garden-service/test/src/cli/helpers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (C) 2018 Garden Technologies, Inc. <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { expect } from "chai"
import { getPackageVersion } from "../../../src/cli/helpers"

describe("helpers", () => {
describe("getPackageVersion", () => {
it("returns the version in package.json", async () => {
const version = require("../../../package.json").version
expect(getPackageVersion()).to.eq(version)
})
})
})
19 changes: 19 additions & 0 deletions garden-service/test/src/commands/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { expect } from "chai"
import { VersionCommand } from "../../../src/commands/version"
import { makeTestGardenA } from "../../helpers"

describe("VersionCommand", () => {
it("should return the current package's version", async () => {
const command = new VersionCommand()
const garden = await makeTestGardenA()
const log = garden.log
const result = await command.action({
log,
garden,
args: {},
opts: {},
})

expect(result.result).to.eql(require("../../../package.json").version)
})
})

0 comments on commit 8be4761

Please sign in to comment.