Skip to content

Commit

Permalink
feat(cli): include provider info in cdktf debug
Browse files Browse the repository at this point in the history
  • Loading branch information
Maed223 committed Oct 16, 2023
1 parent e27e310 commit 8ede93e
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 16 deletions.
64 changes: 57 additions & 7 deletions packages/cdktf-cli/src/bin/cmds/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,17 +520,70 @@ export async function output(argv: any) {
}

export async function debug(argv: any) {
const jsonOutput = argv.json;
const debugOutput = await collectDebugInformation();
const config = CdktfConfig.read();
const language = config.language;
const cdktfVersion = await getPackageVersion(language, "cdktf");
if (!cdktfVersion)
throw Errors.External(
"Could not determine cdktf version. Please make sure you are in a directory containing a cdktf project and have all dependencies installed."
);

if (jsonOutput) {
console.log(JSON.stringify(debugOutput, null, 2));
const manager = new DependencyManager(
language,
cdktfVersion,
config.projectDirectory
);
const allProviders = await manager.allProviders();
const debugOutput = await collectDebugInformation();
if (argv.json) {
console.log(
JSON.stringify(
{
...debugOutput,
providers: {
local: allProviders.local.map((provider) => {
return {
provider: `${provider.providerName}@${provider.providerConstraint}`,
terraformProviderVersion: provider.providerVersion,
};
}),
prebuilt: allProviders.prebuilt.map((provider) => {
return {
provider: provider.packageName,
terraformProviderVersion: provider.providerVersion,
prebuiltProviderVersion: provider.packageVersion,
cdktfVersion: provider.cdktfVersion,
};
}),
},
},
null,
2
)
);
} else {
console.log(chalkColour`{bold {greenBright cdktf debug}}`);

Object.entries(debugOutput).forEach(([key, value]) => {
console.log(`${key}: ${value === null ? "null" : value}`);
});

console.log(chalkColour`{bold {yellowBright providers}}`);

for (const provider of allProviders.local) {
console.log(
`${provider.providerName}@${provider.providerConstraint} (LOCAL)
terraform provider version: ${provider.providerVersion}`
);
}
for (const provider of allProviders.prebuilt) {
console.log(
`${provider.packageName} (PREBUILT)
terraform provider version: ${provider.providerVersion}
prebuilt provider version: ${provider.packageVersion}
cdktf version: ${provider.cdktfVersion}`
);
}
}
}

Expand Down Expand Up @@ -628,7 +681,6 @@ export async function providerList(argv: any) {
const config = CdktfConfig.read();
const language = config.language;
const cdktfVersion = await getPackageVersion(language, "cdktf");

if (!cdktfVersion)
throw Errors.External(
"Could not determine cdktf version. Please make sure you are in a directory containing a cdktf project and have all dependencies installed."
Expand All @@ -639,9 +691,7 @@ export async function providerList(argv: any) {
cdktfVersion,
config.projectDirectory
);

const allProviders = await manager.allProviders();

if (argv.json) {
console.log(JSON.stringify(allProviders));
return;
Expand Down
24 changes: 15 additions & 9 deletions website/docs/cdktf/cli-reference/commands.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -657,18 +657,24 @@ The debug information depends on the programming language. The following example

```
$ cdktf debug
language: java
cdktf-cli: 0.10.4
node: v16.15.0
cdktf: 0.10.4
constructs: 10.0.5
cdktf-cli: 0.18.2
node: v18.18.1
cdktf: 0.18.2
constructs: 10.3.0
jsii: 1.59.0
terraform: 1.1.8
arch: x64
os: darwin 21.4.0
terraform: 1.5.5
arch: arm64
os: darwin 22.6.0
java: 17.0.1
maven: Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)Maven home: /usr/local/Cellar/maven/3.8.2/libexecJava version: 17.0.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/HomeDefault locale: en_DE, platform encoding: UTF-8OS name: "mac os x", version: "12.3.1", arch: "x86_64", family: "mac"
maven: Apache Maven 3.8.2 (ea98e05a04480131370aa0c110b8c54cf726c06f)Maven home: /usr/local/Cellar/maven/3.8.2/libexecJava version: 17.0.1, vendor: Homebrew, runtime: /usr/local/Cellar/openjdk/17.0.1_1/libexec/openjdk.jdk/Contents/HomeDefault locale: en_DE, platform encoding: UTF-8OS name: "mac os x", version: "12.3.1", arch: "arm64", family: "mac"
providers
kreuzwerker/docker@~> 2.0 (LOCAL)
terraform provider version: 2.25.0
@cdktf/provider-ad (PREBUILT)
terraform provider version: 0.4.4
prebuilt provider version: 6.0.0
cdktf version: ^0.18.0
```

## provider add
Expand Down

0 comments on commit 8ede93e

Please sign in to comment.