Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add log4brains adr list by tag in cli #83

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ export function createCli({ appConsole }: Deps): commander.Command {
"Filter on the given statuses, comma-separated"
) // TODO: list available statuses
.option("-r, --raw", "Use a raw format instead of a table", false)
.option("-t, --tags <tags>", "Filter on the given tags, comma-separated")
.description("List ADRs")
.action(
(opts: ListCommandOpts): Promise<void> => {
Expand Down
4 changes: 4 additions & 0 deletions packages/cli/src/commands/ListCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Deps = {

export type ListCommandOpts = {
statuses: string;
tags: string;
raw: boolean;
};

Expand All @@ -26,6 +27,9 @@ export class ListCommand {
if (opts.statuses) {
filters.statuses = opts.statuses.split(",") as AdrDtoStatus[];
}
if (opts.tags) {
filters.tags = opts.tags.split(",");
}
const adrs = await this.l4bInstance.searchAdrs(filters);
const table = this.console.createTable({
head: ["Slug", "Status", "Package", "Title"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { Query } from "@src/application";

export type SearchAdrsFilters = {
statuses?: AdrStatus[];
tags?: string[];
};

export class SearchAdrsQuery extends Query {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ export class SearchAdrsQueryHandler implements QueryHandler {
) {
return false;
}
if (query.filters.tags) {
return query.filters.tags.some((tag) => {
return adr.tags.includes(tag);
});
}
return true;
});
}
Expand Down
4 changes: 4 additions & 0 deletions packages/core/src/infrastructure/api/Log4brains.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { FileWatcher } from "../file-watcher";

export type SearchAdrsFilters = {
statuses?: AdrDtoStatus[];
tags?: string[];
};

/**
Expand Down Expand Up @@ -71,6 +72,9 @@ export class Log4brains {
AdrStatus.createFromName(status)
);
}
if (filters?.tags) {
appFilters.tags = filters.tags;
}
const adrs = await this.queryBus.dispatch<Adr[]>(
new SearchAdrsQuery(appFilters)
);
Expand Down