Skip to content

Commit

Permalink
feat: insight commands checking for interactive
Browse files Browse the repository at this point in the history
  • Loading branch information
field123 committed Sep 22, 2023
1 parent 9b9c7dd commit 6eacf15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 3 deletions.
20 changes: 18 additions & 2 deletions packages/composable-cli/src/commands/insights/insights-command.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import yargs from "yargs"
import { CommandContext, CommandHandlerFunction } from "../../types/command"
import {
CommandContext,
CommandHandlerFunction,
RootCommandArguments,
} from "../../types/command"
import { handleErrors } from "../../util/error-handler"
import {
InsightsCommandArguments,
Expand All @@ -9,10 +13,11 @@ import {
import { promptOptInProductInsights } from "../../lib/insights/opt-in-product-insights-middleware"
import { optInsights } from "../../util/has-opted-insights"
import { trackCommandHandler } from "../../util/track-command-handler"
import { isTTY } from "../../util/is-tty"

export function createInsightsCommand(
ctx: CommandContext
): yargs.CommandModule<{}, InsightsCommandArguments> {
): yargs.CommandModule<RootCommandArguments, InsightsCommandArguments> {
return {
command: "insights",
describe: "opt in/out product insights",
Expand All @@ -39,6 +44,17 @@ export function createInsightsCommandHandler(
InsightsCommandArguments
> {
return async function configCommandHandler(args) {
if (!args.interactive || !isTTY()) {
console.warn("When not interactive, the opt-in flag must be provided.")
return {
success: false,
error: {
code: "not-interactive",
message: "When not interactive, the opt-in flag must be provided.",
},
}
}

if (args.optIn === undefined) {
await promptOptInProductInsights(ctx.store)
return {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { RootCommandArguments } from "../../types/command"

export type InsightsCommandData = {}

export type InsightsCommandError = {
Expand All @@ -8,4 +10,4 @@ export type InsightsCommandError = {
export type InsightsCommandArguments = {
"opt-in"?: boolean
optIn?: boolean
}
} & RootCommandArguments

0 comments on commit 6eacf15

Please sign in to comment.