Skip to content

Commit

Permalink
feat: added prompt when no path for output specified
Browse files Browse the repository at this point in the history
  • Loading branch information
K1NXZ committed Oct 4, 2023
1 parent ee387ca commit 0aee46a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "envshare-cli",
"version": "1.1.0",
"version": "1.2.0",
"description": "A cli to share your environment variables with your team quickly.",
"main": "./dist/esm/index.js",
"bin": {
Expand Down Expand Up @@ -33,7 +33,8 @@
"base-x": "^4.0.0",
"commander": "^11.0.0",
"copy-paste": "^1.5.3",
"inquirer": "^9.2.11"
"inquirer": "^9.2.11",
"untildify": "^5.0.0"
},
"devDependencies": {
"@types/copy-paste": "^1.1.31",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 19 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import path from 'node:path'
import { decrypt, encrypt } from './lib/encryption.js'
import { fromBase58, toBase58 } from './lib/base58.js'
import ncp from 'copy-paste'
import untildify from 'untildify'

const program = new Command().name('envshare-cli').version('1.0.0')

Expand Down Expand Up @@ -136,14 +137,26 @@ program
.argument('ID', 'ID of the env file to fetch')
.option('-o, --output <path>', 'Output file')
.action(async (ID, { output }) => {
let newOutput = output
try {
const content = await fetchFile(ID)
if (output) {
await fs.writeFile(output, content)
console.log(`File written to ${output}`)
return
if (!output) {
const answers = await inquirer.prompt({
type: 'input',
name: 'filename',
message: 'Enter filename to save to',
default: '.env',
})
newOutput = answers.filename
}
} catch {

newOutput = untildify(newOutput!)

const content = await fetchFile(ID)
await fs.writeFile(newOutput!, content)
console.log(`File written to ${newOutput}`)
await fs.writeFile(newOutput!, content)
} catch (e) {
console.log(e)
console.error(`ID ${ID} not found`)
}
})
Expand Down

0 comments on commit 0aee46a

Please sign in to comment.