diff --git a/src/commands/login/index.ts b/src/commands/login/index.ts index 044d53ae..fd082318 100644 --- a/src/commands/login/index.ts +++ b/src/commands/login/index.ts @@ -1,7 +1,7 @@ import chalk from 'chalk' import { input, password, select } from '@inquirer/prompts' import type { RegionCode } from '../../constants' -import { commands, regionNames, regions, regionsDomain } from '../../constants' +import { colorPalette, commands, regionNames, regions, regionsDomain } from '../../constants' import { getProgram } from '../../program' import { CommandError, handleError, isRegion, konsola } from '../../utils' import { loginWithEmailAndPassword, loginWithOtp, loginWithToken } from './actions' @@ -40,7 +40,7 @@ export const loginCommand = program token: string region: RegionCode }) => { - konsola.title(` ${commands.LOGIN} `, '#8556D3') + konsola.title(` ${commands.LOGIN} `, colorPalette.LOGIN) const verbose = program.opts().verbose const { token, region } = options if (!isRegion(region)) { @@ -122,7 +122,7 @@ export const loginCommand = program updateSession(userEmail, response.access_token, userRegion) } await persistCredentials(regionsDomain[userRegion]) - konsola.ok(`Successfully logged in with email ${chalk.hex('#45bfb9')(userEmail)}`) + konsola.ok(`Successfully logged in with email ${chalk.hex(colorPalette.PRIMARY)(userEmail)}`) } } catch (error) { diff --git a/src/commands/user/actions.test.ts b/src/commands/user/actions.test.ts index 233a2702..d6f44f44 100644 --- a/src/commands/user/actions.test.ts +++ b/src/commands/user/actions.test.ts @@ -1,4 +1,3 @@ -import { ofetch } from 'ofetch' import chalk from 'chalk' import { getUser } from './actions' import { http, HttpResponse } from 'msw' diff --git a/src/commands/user/index.ts b/src/commands/user/index.ts index fce06f56..a2dacda9 100644 --- a/src/commands/user/index.ts +++ b/src/commands/user/index.ts @@ -1,8 +1,8 @@ import chalk from 'chalk' import type { NetrcMachine } from '../../creds' -import { commands } from '../../constants' +import { colorPalette, commands } from '../../constants' import { getProgram } from '../../program' -import { formatHeader, handleError, konsola } from '../../utils' +import { CommandError, handleError, konsola } from '../../utils' import { getUser } from './actions' import { session } from '../../session' @@ -12,19 +12,18 @@ export const userCommand = program .command(commands.USER) .description('Get the current user') .action(async () => { - console.log(formatHeader(chalk.bgHex('#8556D3').bold.white(` ${commands.USER} `))) + konsola.title(` ${commands.USER} `, colorPalette.USER) const { state, initializeSession } = session() await initializeSession() if (!state.isLoggedIn) { - konsola.error(new Error(`You are not logged in. Please login first. - `)) + handleError(new CommandError(`You are currently not logged in. Please login first to get your user info.`)) return } try { const { password, region } = state as NetrcMachine const { user } = await getUser(password, region) - konsola.ok(`Hi ${chalk.bold(user.friendly_name)}, you are currently logged in with ${chalk.hex('#45bfb9')(user.email)} on ${chalk.bold(region)} region`) + konsola.ok(`Hi ${chalk.bold(user.friendly_name)}, you are currently logged in with ${chalk.hex(colorPalette.PRIMARY)(user.email)} on ${chalk.bold(region)} region`) } catch (error) { handleError(error as Error, true) diff --git a/src/constants.ts b/src/constants.ts index ac12733d..cc527b28 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -4,6 +4,12 @@ export const commands = { USER: 'user', } as const +export const colorPalette = { + PRIMARY: '#45bfb9', + LOGIN: '#8556D3', + USER: '#8BC34A', // Changed to a less saturated green color +} as const + export interface ReadonlyArray { includes: (searchElement: any, fromIndex?: number) => searchElement is T } diff --git a/src/creds.ts b/src/creds.ts index 29f2a116..ecdae14e 100644 --- a/src/creds.ts +++ b/src/creds.ts @@ -2,7 +2,7 @@ import { access, readFile, writeFile } from 'node:fs/promises' import { join } from 'node:path' import { FileSystemError, handleFileSystemError, konsola } from './utils' import chalk from 'chalk' -import { regionCodes } from './constants' +import { colorPalette, regionCodes } from './constants' export interface NetrcMachine { login: string @@ -186,7 +186,7 @@ export const addNetrcEntry = async ({ mode: 0o600, // Set file permissions }) - konsola.ok(`Successfully added/updated entry for machine ${machineName} in ${chalk.hex('#45bfb9')(filePath)}`, true) + konsola.ok(`Successfully added/updated entry for machine ${machineName} in ${chalk.hex(colorPalette.PRIMARY)(filePath)}`, true) } catch (error) { throw new FileSystemError('invalid_argument', 'write', error as NodeJS.ErrnoException, `Error adding/updating entry for machine ${machineName} in .netrc file`) @@ -223,7 +223,7 @@ export const removeNetrcEntry = async ( mode: 0o600, // Set file permissions }) - konsola.ok(`Successfully removed entry from ${chalk.hex('#45bfb9')(filePath)}`, true) + konsola.ok(`Successfully removed entry from ${chalk.hex(colorPalette.PRIMARY)(filePath)}`, true) } } catch (error: unknown) { diff --git a/src/index.ts b/src/index.ts index c47fca6b..c378fe7a 100644 --- a/src/index.ts +++ b/src/index.ts @@ -48,7 +48,6 @@ ${chalk.hex('#45bfb9')(' |/ ')} try { program.parse(process.argv) - konsola.br() // Add a line break } catch (error) { handleError(error as Error)