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

fix: pass only cmd str to printCommandLogger #203

Merged
merged 3 commits into from
Feb 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -434,17 +434,17 @@ export interface $BuiltInProperties<TExtras extends ExtrasObject = {}> {
* Sets the logger used for info logging.
* @default console.error
*/
setInfoLogger(logger: (args: any[]) => void): void;
setInfoLogger(logger: (...args: any[]) => void): void;
/**
* Sets the logger used for warn logging.
* @default console.error
*/
setWarnLogger(logger: (args: any[]) => void): void;
setWarnLogger(logger: (...args: any[]) => void): void;
/**
* Sets the logger used for error logging.
* @default console.error
*/
setErrorLogger(logger: (args: any[]) => void): void;
setErrorLogger(logger: (...args: any[]) => void): void;
/**
* Mutates the internal command builder to print the command text by
* default before executing commands instead of needing to build a
Expand Down Expand Up @@ -736,18 +736,20 @@ function build$FromState<TExtras extends ExtrasObject = {}>(state: $State<TExtra
state.infoLogger.getValue()(...data);
}, opts);
},
setInfoLogger(logger: (args: any[]) => void) {
setInfoLogger(logger: (...args: any[]) => void) {
state.infoLogger.setValue(logger);
},
setWarnLogger(logger: (args: any[]) => void) {
setWarnLogger(logger: (...args: any[]) => void) {
state.warnLogger.setValue(logger);
},
setErrorLogger(logger: (args: any[]) => void) {
setErrorLogger(logger: (...args: any[]) => void) {
state.errorLogger.setValue(logger);

// also update the logger used for the print command
const commandBuilder = state.commandBuilder.getValue();
commandBuilder.setPrintCommandLogger(logger);
commandBuilder.setPrintCommandLogger(
(cmd) => logger(colors.white(">"), colors.blue(cmd)),
);
state.commandBuilder.setValue(commandBuilder);
},
setPrintCommand(value: boolean) {
Expand Down
8 changes: 5 additions & 3 deletions src/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,10 @@ export class CommandBuilder implements PromiseLike<CommandResult> {
commands: { ...builtInCommands },
exportEnv: false,
printCommand: false,
// deno-lint-ignore no-console
printCommandLogger: new LoggerTreeBox(console.error),
printCommandLogger: new LoggerTreeBox(
// deno-lint-ignore no-console
(cmd) => console.error(colors.white(">"), colors.blue(cmd)),
),
timeout: undefined,
signal: undefined,
};
Expand Down Expand Up @@ -681,7 +683,7 @@ export function parseAndSpawnCommand(state: CommandBuilderState) {
}

if (state.printCommand) {
state.printCommandLogger.getValue()(colors.white(">"), colors.blue(state.command.text));
state.printCommandLogger.getValue()(state.command.text);
}

const disposables: Disposable[] = [];
Expand Down
Loading