Skip to content

Commit

Permalink
chore(cli): remove json flag
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielMSchmidt committed Mar 22, 2022
1 parent c343466 commit e4f479c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 41 deletions.
4 changes: 0 additions & 4 deletions packages/cdktf-cli/bin/cmds/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,6 @@ export async function synth(argv: any) {
const checkCodeMakerOutput = argv.checkCodeMakerOutput;
const command = argv.app;
const outDir = argv.output;
const jsonOutput = argv.json;
const stack = argv.stack;

if (checkCodeMakerOutput && !(await fs.pathExists(config.codeMakerOutput))) {
console.error(
Expand All @@ -270,9 +268,7 @@ export async function synth(argv: any) {
await renderInk(
React.createElement(Synth, {
outDir,
targetStack: stack,
synthCommand: command,
jsonOutput: jsonOutput,
})
);
}
Expand Down
7 changes: 1 addition & 6 deletions packages/cdktf-cli/bin/cmds/synth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { Errors } from "../../lib/errors";
const config = cfg.readConfigSync();

class Command implements yargs.CommandModule {
public readonly command = "synth [stack] [OPTIONS]";
public readonly command = "synth [OPTIONS]";
public readonly describe =
"Synthesizes Terraform code for the given app in a directory.";
public readonly aliases = ["synthesize"];
Expand All @@ -27,11 +27,6 @@ class Command implements yargs.CommandModule {
desc: "Output directory for the synthesized Terraform config",
alias: "o",
})
.option("json", {
type: "boolean",
desc: "Provide JSON output for the generated Terraform configuration.",
default: false,
})
.option("check-code-maker-output", {
type: "boolean",
desc: "Should `codeMakerOutput` existence check be performed? By default it will be checked if providers or modules are configured.",
Expand Down
38 changes: 7 additions & 31 deletions packages/cdktf-cli/bin/cmds/ui/synth.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from "react";
import { Box, Text } from "ink";
import { Text } from "ink";

import { useCdktfProject } from "./hooks/cdktf-project";
import { StreamView } from "./components";
Expand All @@ -8,46 +8,26 @@ import { StatusBottomBar } from "./components/bottom-bars/status";

interface CommonSynthConfig {
outDir: string;
targetStack: string;
jsonOutput: boolean;
}

interface SynthConfig extends CommonSynthConfig {
synthCommand: string;
}
type SynthOutputConfig = {
jsonOutput: boolean;
currentStackName: string;
stacks: SynthesizedStack[];
};
const SynthOutput = ({
jsonOutput,
currentStackName,
stacks,
}: SynthOutputConfig): React.ReactElement => {
const stack =
stacks.find((item) => item.name === currentStackName) || stacks[0];
const SynthOutput = ({ stacks }: SynthOutputConfig): React.ReactElement => {
return (
<>
{jsonOutput && stack ? (
<Box>
<Text>{stack.content}</Text>
</Box>
) : (
<Text>
Generated Terraform code for the stacks:{" "}
{stacks?.map((s) => s.name).join(", ")}
</Text>
)}
</>
<Text>
Generated Terraform code for the stacks:{" "}
{stacks?.map((s) => s.name).join(", ")}
</Text>
);
};

export const Synth = ({
outDir,
synthCommand,
jsonOutput,
targetStack,
}: SynthConfig): React.ReactElement => {
const { returnValue, logEntries, status } = useCdktfProject(
{ outDir, synthCommand },
Expand All @@ -57,11 +37,7 @@ export const Synth = ({
return (
<StreamView logs={logEntries}>
<StatusBottomBar status={status}>
<SynthOutput
jsonOutput={jsonOutput}
currentStackName={targetStack}
stacks={status.type === "done" ? returnValue! : []}
/>
<SynthOutput stacks={status.type === "done" ? returnValue! : []} />
</StatusBottomBar>
</StreamView>
);
Expand Down

0 comments on commit e4f479c

Please sign in to comment.