Skip to content

Commit

Permalink
feat(cli): GARDEN_DISABLE_WEB_APP_WARN flag to mute cloud login warn (
Browse files Browse the repository at this point in the history
#6320)

* refactor(cli): helper to emit login warning

* refactor(cli): inline redundant local vars

Each one is used only once.

* feat(cli): env var to mute cloud login warning
  • Loading branch information
vvagaytsev authored Jul 25, 2024
1 parent aa3ddcc commit 4157472
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 22 deletions.
22 changes: 10 additions & 12 deletions core/src/cli/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import { intersection, mapValues, sortBy } from "lodash-es"
import { resolve, join } from "path"
import fsExtra from "fs-extra"
const { pathExists } = fsExtra
import { getBuiltinCommands } from "../commands/commands.js"
import { getCloudDistributionName } from "../util/cloud.js"
import { shutdown, getPackageVersion } from "../util/util.js"
Expand All @@ -35,7 +34,7 @@ import {
checkRequirements,
renderCommandErrors,
cliStyles,
getDashboardInfoMsg,
emitLoginWarning,
} from "./helpers.js"
import type { ParameterObject, GlobalOptions, ParameterValues } from "./params.js"
import { globalOptions, OUTPUT_RENDERERS } from "./params.js"
Expand Down Expand Up @@ -68,6 +67,8 @@ import { JsonFileWriter } from "../logger/writers/json-file-writer.js"
import type minimist from "minimist"
import { styles } from "../logger/styles.js"

const { pathExists } = fsExtra

export interface RunOutput {
argv: any
code: number
Expand Down Expand Up @@ -319,16 +320,13 @@ ${renderCommands(commands)}
garden = await makeDummyGarden(workingDir, contextOpts)
} else {
garden = await wrapActiveSpan("initializeGarden", () => this.getGarden(workingDir, contextOpts))
const isLoggedIn = !!cloudApi
const isCommunityEdition = garden.cloudDomain === DEFAULT_GARDEN_CLOUD_DOMAIN

if (!isLoggedIn && isCommunityEdition) {
await garden.emitWarning({
key: "web-app",
log,
message: "\n" + getDashboardInfoMsg(),
})
}

await emitLoginWarning({
garden,
log,
isLoggedIn: !!cloudApi,
isCommunityEdition: garden.cloudDomain === DEFAULT_GARDEN_CLOUD_DOMAIN,
})

gardenLog.info(`Running in environment ${styles.highlight(`${garden.environmentName}.${garden.namespace}`)}`)

Expand Down
26 changes: 26 additions & 0 deletions core/src/cli/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type { DeepPrimitiveMap } from "../config/common.js"
import { validateGitInstall } from "../vcs/vcs.js"
import { styles } from "../logger/styles.js"
import { makeDocsLinkStyled } from "../docs/common.js"
import type { Garden } from "../garden.js"

export const cliStyles = {
heading: (str: string) => styles.accent.bold(str),
Expand Down Expand Up @@ -566,6 +567,31 @@ export function renderCommandErrors(logger: Logger, errors: Error[], log?: Log)
}
}

export async function emitLoginWarning({
garden,
log,
isLoggedIn,
isCommunityEdition,
}: {
garden: Garden
log: Log
isLoggedIn: boolean
isCommunityEdition: boolean
}) {
if (gardenEnv.GARDEN_DISABLE_WEB_APP_WARN) {
return
}
if (isLoggedIn || !isCommunityEdition) {
return
}

await garden.emitWarning({
key: "web-app",
log,
message: getDashboardInfoMsg(),
})
}

export function getDashboardInfoMsg() {
return styles.success(deline`
🌿 Log in with ${styles.command(
Expand Down
17 changes: 7 additions & 10 deletions core/src/commands/serve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import type { Garden } from "../garden.js"
import type { GardenPluginReference } from "../plugin/plugin.js"
import { CommandError, ParameterError, isEAddrInUseException, isErrnoException } from "../exceptions.js"
import { styles } from "../logger/styles.js"
import { getDashboardInfoMsg } from "../cli/helpers.js"
import { emitLoginWarning } from "../cli/helpers.js"
import { DEFAULT_GARDEN_CLOUD_DOMAIN } from "../constants.js"

export const defaultServerPort = 9777
Expand Down Expand Up @@ -158,16 +158,13 @@ export class ServeCommand<

try {
const cloudApi = await manager.getCloudApi({ log, cloudDomain, globalConfigStore: garden.globalConfigStore })
const isLoggedIn = !!cloudApi
const isCommunityEdition = cloudDomain === DEFAULT_GARDEN_CLOUD_DOMAIN

if (!isLoggedIn && isCommunityEdition) {
await garden.emitWarning({
key: "web-app",
log,
message: getDashboardInfoMsg(),
})
}
await emitLoginWarning({
garden,
log,
isLoggedIn: !!cloudApi,
isCommunityEdition: cloudDomain === DEFAULT_GARDEN_CLOUD_DOMAIN,
})

if (projectConfig && cloudApi && defaultGarden) {
let projectId = projectConfig?.id
Expand Down
1 change: 1 addition & 0 deletions core/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ export const gardenEnv = {
GARDEN_DISABLE_ANALYTICS: env.get("GARDEN_DISABLE_ANALYTICS").required(false).asBool(),
GARDEN_DISABLE_PORT_FORWARDS: env.get("GARDEN_DISABLE_PORT_FORWARDS").required(false).asBool(),
GARDEN_DISABLE_VERSION_CHECK: env.get("GARDEN_DISABLE_VERSION_CHECK").required(false).asBool(),
GARDEN_DISABLE_WEB_APP_WARN: env.get("GARDEN_DISABLE_WEB_APP_WARN").required(false).default("false").asBool(),
GARDEN_ENABLE_PROFILING: env.get("GARDEN_ENABLE_PROFILING").required(false).default("false").asBool(),
GARDEN_ENVIRONMENT: env.get("GARDEN_ENVIRONMENT").required(false).asString(),
GARDEN_EXPERIMENTAL_BUILD_STAGE: env.get("GARDEN_EXPERIMENTAL_BUILD_STAGE").required(false).asBool(),
Expand Down

0 comments on commit 4157472

Please sign in to comment.