Skip to content

Commit

Permalink
feat: colorPalette constant for command titles
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosabu committed Oct 29, 2024
1 parent 67b426e commit 754d10b
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 14 deletions.
6 changes: 3 additions & 3 deletions src/commands/login/index.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down Expand Up @@ -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)) {
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/commands/user/actions.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { ofetch } from 'ofetch'
import chalk from 'chalk'
import { getUser } from './actions'
import { http, HttpResponse } from 'msw'
Expand Down
11 changes: 5 additions & 6 deletions src/commands/user/index.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand All @@ -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)

Check failure on line 15 in src/commands/user/index.ts

View workflow job for this annotation

GitHub Actions / Test (20)

src/commands/user/index.test.ts > userCommand > should show the user information

TypeError: konsola.title is not a function ❯ Command.<anonymous> src/commands/user/index.ts:15:13 ❯ Command.listener [as _actionHandler] node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:542:17 ❯ node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1502:14 ❯ Command._chainOrCall node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1386:12 ❯ Command._parseCommand node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1501:27 ❯ Command.parseAsync node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1092:16 ❯ src/commands/user/index.test.ts:71:23

Check failure on line 15 in src/commands/user/index.ts

View workflow job for this annotation

GitHub Actions / Test (20)

src/commands/user/index.test.ts > userCommand > should show an error if the user is not logged in

TypeError: konsola.title is not a function ❯ Command.<anonymous> src/commands/user/index.ts:15:13 ❯ Command.listener [as _actionHandler] node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:542:17 ❯ node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1502:14 ❯ Command._chainOrCall node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1386:12 ❯ Command._parseCommand node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1501:27 ❯ Command.parseAsync node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1092:16 ❯ src/commands/user/index.test.ts:83:23

Check failure on line 15 in src/commands/user/index.ts

View workflow job for this annotation

GitHub Actions / Test (20)

src/commands/user/index.test.ts > userCommand > should show an error if the user information cannot be fetched

TypeError: konsola.title is not a function ❯ Command.<anonymous> src/commands/user/index.ts:15:13 ❯ Command.listener [as _actionHandler] node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:542:17 ❯ node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1502:14 ❯ Command._chainOrCall node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1386:12 ❯ Command._parseCommand node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1501:27 ❯ Command.parseAsync node_modules/.pnpm/commander@12.1.0/node_modules/commander/lib/command.js:1092:16 ❯ src/commands/user/index.test.ts:100:23
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)
Expand Down
6 changes: 6 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> {
includes: (searchElement: any, fromIndex?: number) => searchElement is T
}
Expand Down
6 changes: 3 additions & 3 deletions src/creds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`)
Expand Down Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ ${chalk.hex('#45bfb9')(' |/ ')}

try {
program.parse(process.argv)
konsola.br() // Add a line break
}
catch (error) {
handleError(error as Error)
Expand Down

0 comments on commit 754d10b

Please sign in to comment.