Skip to content

Commit

Permalink
feat: switch to oclif core (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
santese authored Oct 4, 2022
1 parent 52a56a7 commit 086fc12
Show file tree
Hide file tree
Showing 8 changed files with 97 additions and 173 deletions.
29 changes: 15 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "guru-cli",
"version": "1.0.2",
"version": "1.1.1",
"description": "CLI tools for Guru KB (getguru.com)",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
Expand Down Expand Up @@ -43,23 +43,23 @@
"url": "https://github.com/pliancy/guru-cli"
},
"devDependencies": {
"@digitalroute/cz-conventional-changelog-for-jira": "^7.4.0",
"@digitalroute/cz-conventional-changelog-for-jira": "7.4.0",
"@pliancy/eslint-config-ts": "0.1.0",
"@pliancy/semantic-release-config-npm": "^2.2.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^8.0.6",
"@semantic-release/npm": "^9.0.1",
"@pliancy/semantic-release-config-npm": "2.2.0",
"@semantic-release/git": "10.0.1",
"@semantic-release/github": "8.0.6",
"@semantic-release/npm": "9.0.1",
"@types/cli-progress": "3.9.0",
"@types/jest": "^29.1.0",
"@types/jest": "29.1.0",
"@types/node": "17.0.21",
"commitizen": "^4.2.5",
"cz-conventional-changelog": "^3.3.0",
"commitizen": "4.2.5",
"cz-conventional-changelog": "3.3.0",
"husky": "8.0.1",
"jest": "^29.1.1",
"jest": "29.1.1",
"lint-staged": "13.0.3",
"npm-run-all": "^4.1.5",
"npm-run-all": "4.1.5",
"rimraf": "3.0.2",
"semantic-release": "^19.0.5",
"semantic-release": "19.0.5",
"ts-jest": "29.0.3",
"ts-node": "10.9.1",
"typescript": "4.8.4"
Expand All @@ -71,13 +71,14 @@
"node": "14.20.1"
},
"dependencies": {
"@oclif/core": "1.16.4",
"axios": "0.27.2",
"cac": "6.7.2",
"chalk": "4.1.2",
"cli-progress": "3.9.0",
"cli-ux": "6.0.9",
"conf": "10.2.0",
"search-query-parser": "1.5.5"
"search-query-parser": "1.5.5",
"tslib": "2.4.0"
},
"lint-staged": {
"*.{js,jsx,ts,tsx}": [
Expand Down
12 changes: 6 additions & 6 deletions src/commands/find-replace.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import cliux from 'cli-ux'
import { CliUx } from '@oclif/core'

import guru from '../lib/guruClient'
import { GuruCardRaw } from '../lib/guru'
Expand All @@ -22,7 +22,7 @@ export default async (cli: any): Promise<void> => {
)
.action(async (find: string, replace: string, filter: string, options: any) => {
checkAuth()
cliux.action.start('Finding cards based on filter')
CliUx.ux.action.start('Finding cards based on filter')
const cardsRaw = await guru.getAllCardsRaw()
const filteredCards = handleCardsFilter(filter, cardsRaw, options, {
raw: true,
Expand All @@ -34,10 +34,10 @@ export default async (cli: any): Promise<void> => {
)

if (!matchedCards.length) {
cliux.action.stop(`❌ ${matchedCards.length} cards found matching "${find}"`)
CliUx.ux.action.stop(`❌ ${matchedCards.length} cards found matching "${find}"`)
return
}
cliux.action.stop(`✅ ${matchedCards.length} cards found matching "${find}"`)
CliUx.ux.action.stop(`✅ ${matchedCards.length} cards found matching "${find}"`)

if (!options.confirm) {
console.log('Preview:\n------------------------')
Expand Down Expand Up @@ -81,14 +81,14 @@ export default async (cli: any): Promise<void> => {
}

if (!options.force) {
const backup = await cliux.confirm(
const backup = await CliUx.ux.confirm(
'Would you like to backup card data before making changes? (RECOMMENDED) (Y/n)',
)
if (backup) {
await backupCards('./')
}

const confirm = await cliux.confirm(
const confirm = await CliUx.ux.confirm(
`This will replace all instances matching "${chalk.bold.redBright(
find,
)}" with ${chalk.bold.green(replace)} in ${
Expand Down
8 changes: 4 additions & 4 deletions src/commands/find.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cliux from 'cli-ux'
import { CliUx } from '@oclif/core'
import chalk from 'chalk'

import guru from '../lib/guruClient'
Expand Down Expand Up @@ -28,15 +28,15 @@ guru-cli find 'verifier:"^bob@example\\\\.com$"'
.option('-i, --ignore-case', 'Ignore case in the finding regex string')
.action(async (filter: string, options: any) => {
checkAuth()
cliux.action.start('Searching for cards')
CliUx.ux.action.start('Searching for cards')
const cardsRaw = await guru.getAllCardsRaw()
const filteredCards = handleCardsFilter(filter, cardsRaw, options) as GuruCard[]
if (!filteredCards.length) {
cliux.action.stop(`❌ ${filteredCards.length} cards found matching your filter`)
CliUx.ux.action.stop(`❌ ${filteredCards.length} cards found matching your filter`)
return
}

cliux.action.stop(
CliUx.ux.action.stop(
`✅ ${filteredCards.length} cards matching your filter\n---------------------------`,
)
filteredCards.map((card) =>
Expand Down
6 changes: 3 additions & 3 deletions src/commands/login.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import cliux from 'cli-ux'
import { CliUx } from '@oclif/core'

import config from '../config'
import { Guru } from '../lib/guru'
Expand All @@ -7,8 +7,8 @@ export default async (cli: any): Promise<void> => {
cli.command('login', 'login and save credentials for guru cli').action(async () => {
config.clear()
console.log('Login to Guru API\n------------------------')
const email = await cliux.prompt('Guru Admin Email')
const token = await cliux.prompt('Admin API Token')
const email = await CliUx.ux.prompt('Guru Admin Email')
const token = await CliUx.ux.prompt('Admin API Token')
const g = new Guru({
email,
token,
Expand Down
8 changes: 4 additions & 4 deletions src/commands/verify-all.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from 'chalk'
import Progress from 'cli-progress'
import cliux from 'cli-ux'
import { CliUx } from '@oclif/core'

import guru from '../lib/guruClient'
import { GuruCard } from '../lib/guru'
Expand All @@ -20,10 +20,10 @@ export default async (cli: any): Promise<void> => {
.option('-f, --force', 'Skip confirmation, BE CAREFUL WITH THIS OPTION!')
.action(async (filter: string, options: any) => {
checkAuth()
cliux.action.start('Gathering all unverified cards')
CliUx.ux.action.start('Gathering all unverified cards')
const unverifiedCards = await guru.getAllUnverifiedCardsRaw()
const filteredCards = handleCardsFilter(filter, unverifiedCards, options) as GuruCard[]
cliux.action.stop(`✅ ${filteredCards.length} unverified cards found.`)
CliUx.ux.action.stop(`✅ ${filteredCards.length} unverified cards found.`)

if (!filteredCards.length) {
console.log('You have no unverified cards currently!')
Expand All @@ -36,7 +36,7 @@ export default async (cli: any): Promise<void> => {
}

if (!options.force) {
const confirm = await cliux.confirm(
const confirm = await CliUx.ux.confirm(
`This will verify ${filteredCards.length} cards currently in an unverified state. Continue? (Y/n)`,
)
if (!confirm) return
Expand Down
12 changes: 6 additions & 6 deletions src/commands/verify-by-title.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import chalk from 'chalk'
import cliux from 'cli-ux'
import { CliUx } from '@oclif/core'

import guru from '../lib/guruClient'
import { GuruCard } from '../lib/guru'
Expand All @@ -12,7 +12,7 @@ export default async (cli: any): Promise<void> => {

.action(async (title: string, options?: any) => {
checkAuth()
cliux.action.start('Searching for cards')
CliUx.ux.action.start('Searching for cards')
const cardsRaw = await guru.getAllCardsRaw()
let filteredCards = handleCardsFilter(
`title:"^${title}$"`,
Expand All @@ -27,11 +27,11 @@ export default async (cli: any): Promise<void> => {
}

if (!filteredCards.length) {
cliux.action.stop(`❌ ${filteredCards.length} cards found matching your title`)
CliUx.ux.action.stop(`❌ ${filteredCards.length} cards found matching your title`)
return
}

cliux.action.stop(
CliUx.ux.action.stop(
`✅ ${filteredCards.length} card${filteredCards.length > 1 ? 's' : ''} match${
filteredCards.length > 1 ? '' : 'es'
} your collection and title\n---------------------------`,
Expand All @@ -45,12 +45,12 @@ export default async (cli: any): Promise<void> => {
),
)

const confirm = await cliux.confirm(
const confirm = await CliUx.ux.confirm(
'Do you wish to verify the identified card(s)? (Y/n)',
)
if (!confirm) return

cliux.action.start(`Verifying ${title}`)
CliUx.ux.action.start(`Verifying ${title}`)

for (const card of filteredCards) {
await guru.verifyCardByID(card)
Expand Down
8 changes: 4 additions & 4 deletions src/commands/verify-expired.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import chalk from 'chalk'
import Progress from 'cli-progress'
import cliux from 'cli-ux'
import { CliUx } from '@oclif/core'

import guru from '../lib/guruClient'
import { GuruCard } from '../lib/guru'
Expand All @@ -15,10 +15,10 @@ export default async (cli: any): Promise<void> => {
.option('-f, --force', 'Skip confirmation, BE CAREFUL WITH THIS OPTION!')
.action(async (filter: string, options: any) => {
checkAuth()
cliux.action.start('Gathering all expired cards')
CliUx.ux.action.start('Gathering all expired cards')
const expiredCards = await guru.getAllExpiredCardsRaw()
const filteredCards = handleCardsFilter(filter, expiredCards, options) as GuruCard[]
cliux.action.stop(`✅ ${filteredCards.length} expired cards found.`)
CliUx.ux.action.stop(`✅ ${filteredCards.length} expired cards found.`)

if (!filteredCards.length) {
console.log('You have no expired cards currently!')
Expand All @@ -31,7 +31,7 @@ export default async (cli: any): Promise<void> => {
}

if (!options.force) {
const confirm = await cliux.confirm(
const confirm = await CliUx.ux.confirm(
`This will verify ${filteredCards.length} cards currently in expired state. Continue? (Y/n)`,
)
if (!confirm) return
Expand Down
Loading

0 comments on commit 086fc12

Please sign in to comment.