Skip to content

Commit

Permalink
fix(cli): add exclude-disabled option to get config command
Browse files Browse the repository at this point in the history
The dashboard fails to render if there are disabled services in the
config that it loads via the 'get config' command.
  • Loading branch information
eysi09 committed Feb 5, 2020
1 parent 51eeb85 commit 353a05e
Show file tree
Hide file tree
Showing 5 changed files with 394 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dashboard/src/api/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export interface ApiRequest {
const MAX_LOG_LINES = 5000

export async function fetchConfig() {
return apiPost<ConfigDump>("get.config")
return apiPost<ConfigDump>("get.config", { "exclude-disabled": true })
}

export async function fetchGraph() {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/src/containers/overview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ export default () => {
}

const moduleProps: ModuleProps[] = Object.values(modules).map((module: Module) => {
const serviceEntities = module.services.map((serviceKey) => services[serviceKey]) || []
const testEntities = module.tests.map((testKey) => tests[testKey]) || []
const taskEntities = module.tasks.map((taskKey) => tasks[taskKey]) || []
const serviceEntities = module.services.map((serviceKey) => services[serviceKey]).filter(Boolean)
const testEntities = module.tests.map((testKey) => tests[testKey]).filter(Boolean)
const taskEntities = module.tasks.map((taskKey) => tasks[taskKey]).filter(Boolean)

return {
name: module.name,
Expand Down
8 changes: 7 additions & 1 deletion docs/reference/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ Outputs the fully resolved configuration for this project and environment.

##### Usage

garden get config
garden get config [options]

##### Options

| Argument | Alias | Type | Description |
| -------- | ----- | ---- | ----------- |
| `--exclude-disabled` | | boolean | Exclude disabled module, service, test, and task configs from output.

### garden get eysi

Expand Down
31 changes: 28 additions & 3 deletions garden-service/src/commands/get/get-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,41 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { Command, CommandResult, CommandParams } from "../base"
import { Command, CommandResult, CommandParams, BooleanParameter } from "../base"
import { ConfigDump } from "../../garden"

export class GetConfigCommand extends Command {
const options = {
"exclude-disabled": new BooleanParameter({
help: "Exclude disabled module, service, test, and task configs from output.",
}),
}

type Opts = typeof options

export class GetConfigCommand extends Command<{}, Opts> {
name = "config"
help = "Outputs the fully resolved configuration for this project and environment."
options = options

async action({ garden, log }: CommandParams): Promise<CommandResult<ConfigDump>> {
async action({ garden, log, opts }: CommandParams<{}, Opts>): Promise<CommandResult<ConfigDump>> {
const config = await garden.dumpConfig(log)

if (opts["exclude-disabled"]) {
const filteredModuleConfigs = config.moduleConfigs
.filter((moduleConfig) => !moduleConfig.disabled)
.map((moduleConfig) => {
const filteredConfig = {
...moduleConfig,
serviceConfigs: moduleConfig.serviceConfigs.filter((c) => !c.disabled),
taskConfigs: moduleConfig.taskConfigs.filter((c) => !c.disabled),
testConfigs: moduleConfig.testConfigs.filter((c) => !c.disabled),
}
return filteredConfig
})

config.moduleConfigs = filteredModuleConfigs
}

// TODO: do a nicer print of this by default
log.info({ data: config })

Expand Down
Loading

0 comments on commit 353a05e

Please sign in to comment.