Skip to content
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
2 changes: 2 additions & 0 deletions packages/atxp/src/call-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { atxpClient, ATXPAccount } from '@atxp/client';
import chalk from 'chalk';
import { getConnection } from './config.js';
import { FileOAuthDb } from './file-oauth-db.js';
import { getCliLogger } from './verbose.js';

let oAuthDb: FileOAuthDb | null = null;
function getOAuthDb(): FileOAuthDb {
Expand Down Expand Up @@ -33,6 +34,7 @@ export async function callTool(
mcpServer: `https://${server}`,
account: new ATXPAccount(connection),
oAuthDb: getOAuthDb(),
logger: getCliLogger(),
});

const result = (await client.callTool({
Expand Down
4 changes: 4 additions & 0 deletions packages/atxp/src/help.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ export function showHelp(): void {
console.log(' npx atxp <command> [options]');
console.log();

console.log(chalk.bold('Global Options:'));
console.log(' ' + chalk.yellow('--verbose, -v') + ' ' + 'Enable verbose output (OAuth debug logs)');
console.log();

console.log(chalk.bold('Authentication:'));
console.log(' ' + chalk.cyan('login') + ' ' + 'Log in to ATXP (save connection string)');
console.log();
Expand Down
103 changes: 103 additions & 0 deletions packages/atxp/src/verbose.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import { describe, it, expect, beforeEach, afterEach } from 'vitest';

describe('Verbose Mode', () => {
let originalArgv: string[];
let originalDebug: string | undefined;

beforeEach(() => {
originalArgv = process.argv;
originalDebug = process.env.DEBUG;
});

afterEach(() => {
process.argv = originalArgv;
if (originalDebug === undefined) {
delete process.env.DEBUG;
} else {
process.env.DEBUG = originalDebug;
}
});

describe('isVerboseMode', () => {
it('should return true when --verbose flag is present', async () => {
process.argv = ['node', 'atxp', 'search', '--verbose'];
delete process.env.DEBUG;

// Re-import to get fresh evaluation
const { isVerboseMode } = await import('./verbose.js');
expect(isVerboseMode()).toBe(true);
});

it('should return true when -v flag is present', async () => {
process.argv = ['node', 'atxp', 'search', '-v'];
delete process.env.DEBUG;

const { isVerboseMode } = await import('./verbose.js');
expect(isVerboseMode()).toBe(true);
});

it('should return true when DEBUG=atxp is set', async () => {
process.argv = ['node', 'atxp', 'search'];
process.env.DEBUG = 'atxp';

const { isVerboseMode } = await import('./verbose.js');
expect(isVerboseMode()).toBe(true);
});

it('should return true when DEBUG=1 is set', async () => {
process.argv = ['node', 'atxp', 'search'];
process.env.DEBUG = '1';

const { isVerboseMode } = await import('./verbose.js');
expect(isVerboseMode()).toBe(true);
});

it('should return true when DEBUG=true is set', async () => {
process.argv = ['node', 'atxp', 'search'];
process.env.DEBUG = 'true';

const { isVerboseMode } = await import('./verbose.js');
expect(isVerboseMode()).toBe(true);
});

it('should return true when DEBUG contains atxp', async () => {
process.argv = ['node', 'atxp', 'search'];
process.env.DEBUG = 'other,atxp,more';

const { isVerboseMode } = await import('./verbose.js');
expect(isVerboseMode()).toBe(true);
});

it('should return false when no verbose indicators are present', async () => {
process.argv = ['node', 'atxp', 'search'];
delete process.env.DEBUG;

const { isVerboseMode } = await import('./verbose.js');
expect(isVerboseMode()).toBe(false);
});

it('should return false when DEBUG is set to unrelated value', async () => {
process.argv = ['node', 'atxp', 'search'];
process.env.DEBUG = 'other';

const { isVerboseMode } = await import('./verbose.js');
expect(isVerboseMode()).toBe(false);
});
});

describe('getCliLogger', () => {
it('should return a ConsoleLogger instance', async () => {
process.argv = ['node', 'atxp', 'search'];
delete process.env.DEBUG;

const { getCliLogger } = await import('./verbose.js');
const logger = getCliLogger();

expect(logger).toBeDefined();
expect(typeof logger.debug).toBe('function');
expect(typeof logger.info).toBe('function');
expect(typeof logger.warn).toBe('function');
expect(typeof logger.error).toBe('function');
});
});
});
15 changes: 15 additions & 0 deletions packages/atxp/src/verbose.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ConsoleLogger, LogLevel } from '@atxp/common';

export function isVerboseMode(): boolean {
if (process.argv.includes('--verbose') || process.argv.includes('-v')) {
return true;
}
const debug = process.env.DEBUG?.toLowerCase();
return debug === '1' || debug === 'true' || debug?.includes('atxp') === true;
}

export function getCliLogger(): ConsoleLogger {
return new ConsoleLogger({
level: isVerboseMode() ? LogLevel.DEBUG : LogLevel.WARN,
});
}
Loading