Skip to content

Commit

Permalink
fix: don't crash running collie info outside of a git repo
Browse files Browse the repository at this point in the history
  • Loading branch information
JohannesRudolph committed Sep 22, 2023
1 parent 1815d35 commit 1ab7114
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 25 deletions.
5 changes: 2 additions & 3 deletions src/api/CliApiFacadeFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ import { TerraformCliFacade } from "./terraform/TerraformCliFacade.ts";

export class CliApiFacadeFactory {
constructor(
private readonly repo: CollieRepository,
private readonly logger: Logger,
) {}

Expand Down Expand Up @@ -155,7 +154,7 @@ export class CliApiFacadeFactory {
return new NpmCliFacade(processRunner);
}

public buildTerraformDocs() {
public buildTerraformDocs(repo: CollieRepository) {
const quietRunner = this.buildQuietLoggingProcessRunner();
const detector = new TerraformDocsCliDetector(quietRunner);

Expand All @@ -164,7 +163,7 @@ export class CliApiFacadeFactory {
new ProcessRunnerErrorResultHandler(detector),
);

return new TerraformDocsCliFacade(this.repo, processRunner);
return new TerraformDocsCliFacade(repo, processRunner);
}

public buildTerraform() {
Expand Down
2 changes: 1 addition & 1 deletion src/commands/compliance/import.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function registerImportCmd(program: TopLevelCommand) {
const collie = await CollieRepository.load();
const logger = new Logger(collie, opts);

const factory = new CliApiFacadeFactory(collie, logger);
const factory = new CliApiFacadeFactory(logger);
const git = factory.buildGit();

const hub = new CollieHub(git, collie);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/foundation/deploy.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ export async function deployFoundation(
opts: GlobalCommandOptions & DeployOptions,
logger: Logger,
) {
const factory = new CliApiFacadeFactory(repo, logger);
const factory = new CliApiFacadeFactory(logger);

const terragrunt = factory.buildTerragrunt();

Expand Down
4 changes: 2 additions & 2 deletions src/commands/foundation/docs.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ export function registerDocsCmd(program: TopLevelCommand) {
validator,
);

const factory = new CliApiFacadeFactory(repo, logger);
const factory = new CliApiFacadeFactory(logger);
// todo: instead of flags, maybe these should be subcommands?
if (opts.update) {
await updateDocumentation(repo, foundationRepo, logger);
Expand Down Expand Up @@ -108,7 +108,7 @@ async function updateDocumentation(

const analyzer = new KitDependencyAnalyzer(repo, modules, logger);

const factory = new CliApiFacadeFactory(repo, logger);
const factory = new CliApiFacadeFactory(logger);
const terragrunt = factory.buildTerragrunt();
const platformDocumentation = new PlatformDocumentationGenerator(
repo,
Expand Down
2 changes: 1 addition & 1 deletion src/commands/foundation/new.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export function registerNewCmd(program: TopLevelCommand) {

const foundationPath = repo.resolvePath("foundations", foundation);

const factory = new CliApiFacadeFactory(repo, logger);
const factory = new CliApiFacadeFactory(logger);

const platformEntries = await promptPlatformEntries(
foundation,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/info.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export function registerInfoCommand(program: TopLevelCommand) {
console.log(`Runtime:`);
console.log(`deno ${Deno.version.deno} ${Deno.build.target}\n`);

const collie = await CollieRepository.load();
const collie = CollieRepository.uninitialized(".");
const logger = new Logger(collie, opts);

const factory = new CliApiFacadeFactory(collie, logger);
const factory = new CliApiFacadeFactory(logger);

const detectors = factory.buildCliDetectors();

Expand Down
8 changes: 4 additions & 4 deletions src/commands/init.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@ export function registerInitCommand(program: TopLevelCommand) {

// we would like to create the CollieRepository after git has been initialized
// but we need it to build git
const kit = CollieRepository.uninitialized(directory);
const logger = new Logger(kit, opts);
const repo = CollieRepository.uninitialized(directory);
const logger = new Logger(repo, opts);

// ensure git is initialized
const cliFactory = new CliApiFacadeFactory(kit, logger);
const cliFactory = new CliApiFacadeFactory(logger);
const git = cliFactory.buildGit();

await git.init(directory);
Expand Down Expand Up @@ -62,7 +62,7 @@ export function registerInitCommand(program: TopLevelCommand) {
// this is the only place where an absolute path is ok, to show the user unambigously where
// the repository is on their file system
logger.progress(
"generated new collie repository at " + kit.resolvePath(),
"generated new collie repository at " + repo.resolvePath(),
);

logger.tipCommand(
Expand Down
4 changes: 2 additions & 2 deletions src/commands/kit/apply.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ export async function applyKitModule(
...platformModuleId,
);

const factory = new CliApiFacadeFactory(collie, logger);
const tfdocs = factory.buildTerraformDocs();
const factory = new CliApiFacadeFactory(logger);
const tfdocs = factory.buildTerraformDocs(collie);
const kitModulePath = collie.relativePath(
collie.resolvePath("kit", moduleId),
);
Expand Down
2 changes: 1 addition & 1 deletion src/commands/kit/bundle.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ async function selectKitBundle(
foundationRepo: FoundationRepository,
opts: GlobalCommandOptions & BundleOptions,
) {
const factory = new CliApiFacadeFactory(collie, logger);
const factory = new CliApiFacadeFactory(logger);
const az = factory.buildAz();
const locations = (await az.listLocations())
// only physical regions (like "germanywestcentral") should be selectable,
Expand Down
4 changes: 2 additions & 2 deletions src/commands/kit/compile.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ export function registerCompileCmd(program: TopLevelCommand) {
const kitProgress = new ProgressReporter("compiling", "kit", logger);

// todo: should compiling a kit module also run tflint and other stuff?
const factory = new CliApiFacadeFactory(collie, logger);
const factory = new CliApiFacadeFactory(logger);
const tf = factory.buildTerraform();
const tfDocs = factory.buildTerraformDocs();
const tfDocs = factory.buildTerraformDocs(collie);

const modules = moduleRepo.all.filter((x) => !module || module == x.id);

Expand Down
2 changes: 1 addition & 1 deletion src/commands/kit/import.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export function registerImportCmd(program: TopLevelCommand) {
const collie = await CollieRepository.load();
const logger = new Logger(collie, opts);

const factory = new CliApiFacadeFactory(collie, logger);
const factory = new CliApiFacadeFactory(logger);
const git = factory.buildGit();

const hub = new CollieHub(git, collie);
Expand Down
10 changes: 5 additions & 5 deletions src/commands/tenant/prepareTenantCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ export async function prepareTenantCommand(
options: GlobalCommandOptions & TenantCommandOptions,
foundation: string,
) {
const collieRepo = await CollieRepository.load();
const repo = await CollieRepository.load();

const logger = new Logger(collieRepo, options);
const logger = new Logger(repo, options);

const validator = new ModelValidator(logger);

const foundationRepo = await FoundationRepository.load(
collieRepo,
repo,
foundation,
validator,
);

const facadeFactory = new CliApiFacadeFactory(collieRepo, logger);
const facadeFactory = new CliApiFacadeFactory(logger);
const meshAdapterFactory = new MeshFoundationAdapterFactory(
collieRepo,
repo,
foundationRepo,
facadeFactory,
logger,
Expand Down

0 comments on commit 1ab7114

Please sign in to comment.