-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: make collie info detect opentofu or terraform
closes #289
- Loading branch information
1 parent
39aad97
commit 73eef4b
Showing
4 changed files
with
61 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { IProcessRunner } from "../../process/IProcessRunner.ts"; | ||
import { ProcessResultWithOutput } from "../../process/ProcessRunnerResult.ts"; | ||
import { CliDetector } from "../CliDetector.ts"; | ||
|
||
export class OpenTofuCliDetector extends CliDetector { | ||
constructor(runner: IProcessRunner<ProcessResultWithOutput>) { | ||
super("tofu", runner); | ||
} | ||
|
||
protected parseVersion(versionCmdOutput: string): string { | ||
return versionCmdOutput.split("\n")[0].substring("OpenTofu ".length); | ||
} | ||
|
||
protected isSupportedVersion(version: string): boolean { | ||
return CliDetector.testSemverSatisfiesRange(version, ">=1.0.0"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { CliDetectionResult, ICliDetector } from "../CliDetector.ts"; | ||
import { InstallationStatus } from "/api/CliInstallationStatus.ts"; | ||
import { CliInstallationStatusError } from "/errors.ts"; | ||
import { OpenTofuCliDetector } from "./OpenTofuCliDetector.ts"; | ||
import { TerraformCliDetector } from "./TerraformCliDetector.ts"; | ||
|
||
export class TofuOrTerraformCliDetector implements ICliDetector { | ||
constructor( | ||
private readonly tofu: OpenTofuCliDetector, | ||
private readonly terraform: TerraformCliDetector, | ||
) { | ||
} | ||
async detect(): Promise<CliDetectionResult> { | ||
const tofuResult = await this.tofu.detect(); | ||
if (tofuResult.status === InstallationStatus.Installed) { | ||
return tofuResult; | ||
} | ||
|
||
return this.terraform.detect(); | ||
} | ||
|
||
async tryRaiseInstallationStatusError() { | ||
const { status } = await this.detect(); | ||
switch (status) { | ||
case InstallationStatus.Installed: | ||
break; | ||
case InstallationStatus.NotInstalled: | ||
case InstallationStatus.UnsupportedVersion: | ||
throw new CliInstallationStatusError("tofu or terraform", status); | ||
} | ||
} | ||
} |