Skip to content

Commit

Permalink
feat: add force flag to env config command
Browse files Browse the repository at this point in the history
  • Loading branch information
edvald committed May 24, 2018
1 parent 673630c commit d5ba05b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
20 changes: 16 additions & 4 deletions src/commands/environment/configure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,30 @@

import { PluginContext } from "../../plugin-context"
import { EnvironmentStatusMap } from "../../types/plugin/outputs"
import { Command } from "../base"
import {
BooleanParameter,
Command,
ParameterValues,
} from "../base"

export class EnvironmentConfigureCommand extends Command {
export const options = {
force: new BooleanParameter({ help: "Force reconfiguration of module(s)" }),
}

export type Opts = ParameterValues<typeof options>

export class EnvironmentConfigureCommand extends Command<any, Opts> {
name = "configure"
alias = "config"
help = "Configures your environment"

async action(ctx: PluginContext): Promise<EnvironmentStatusMap> {
options = options

async action(ctx: PluginContext, _args, opts: Opts): Promise<EnvironmentStatusMap> {
const { name } = ctx.getEnvironment()
ctx.log.header({ emoji: "gear", command: `Configuring ${name} environment` })

const result = await ctx.configureEnvironment({})
const result = await ctx.configureEnvironment({ force: opts.force })

ctx.log.info("")
ctx.log.header({ emoji: "heavy_check_mark", command: `Done!` })
Expand Down
8 changes: 4 additions & 4 deletions src/plugin-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ export type WrappedFromGarden = Pick<Garden,

export interface PluginContext extends PluginContextGuard, WrappedFromGarden {
getEnvironmentStatus: (params: {}) => Promise<EnvironmentStatusMap>
configureEnvironment: (params: {}) => Promise<EnvironmentStatusMap>
configureEnvironment: (params: { force?: boolean }) => Promise<EnvironmentStatusMap>
destroyEnvironment: (params: {}) => Promise<EnvironmentStatusMap>
getConfig: (params: PluginContextParams<GetConfigParams>) => Promise<GetConfigResult>
setConfig: (params: PluginContextParams<SetConfigParams>) => Promise<SetConfigResult>
Expand Down Expand Up @@ -273,15 +273,15 @@ export function createPluginContext(garden: Garden): PluginContext {
return Bluebird.props(mapValues(handlers, h => h({ ...commonParams(h) })))
},

configureEnvironment: async () => {
configureEnvironment: async ({ force = false }: { force?: boolean }) => {
const handlers = garden.getActionHandlers("configureEnvironment")

const statuses = await ctx.getEnvironmentStatus({})

await Bluebird.each(toPairs(handlers), async ([name, handler]) => {
const status = statuses[name] || { configured: false }

if (status.configured) {
if (status.configured && !force) {
return
}

Expand All @@ -291,7 +291,7 @@ export function createPluginContext(garden: Garden): PluginContext {
msg: "Configuring...",
})

await handler({ ...commonParams(handler), status, logEntry })
await handler({ ...commonParams(handler), force, status, logEntry })

logEntry.setSuccess("Configured")
})
Expand Down
1 change: 1 addition & 0 deletions src/types/plugin/params.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export interface GetEnvironmentStatusParams extends PluginActionParamsBase {

export interface ConfigureEnvironmentParams extends PluginActionParamsBase {
status: EnvironmentStatus
force: boolean
}

export interface DestroyEnvironmentParams extends PluginActionParamsBase {
Expand Down

0 comments on commit d5ba05b

Please sign in to comment.