Skip to content

Commit

Permalink
feat(cli): alias env-file and env options
Browse files Browse the repository at this point in the history
  • Loading branch information
antongolub committed Dec 25, 2024
1 parent 90a4f24 commit 2af3de6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
14 changes: 6 additions & 8 deletions src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function printUsage() {
export const argv = parseArgv(process.argv.slice(2), {
string: ['shell', 'prefix', 'postfix', 'eval', 'cwd', 'ext', 'registry', 'env'],
boolean: ['version', 'help', 'quiet', 'verbose', 'install', 'repl', 'experimental', 'prefer-local'],
alias: { e: 'eval', i: 'install', v: 'version', h: 'help', l: 'prefer-local' },
alias: { e: 'eval', i: 'install', v: 'version', h: 'help', l: 'prefer-local', 'env-file': 'env' },
stopEarly: true,
parseBoolean: true,
camelCase: true,
Expand Down Expand Up @@ -187,14 +187,12 @@ export async function importPath(
filepath: string,
origin = filepath
): Promise<void> {
const ext = path.extname(filepath)
const base = path.basename(filepath)
const dir = path.dirname(filepath)
const { ext, base, dir } = path.parse(filepath)

if (ext === '') {
const tmpFilename = fs.existsSync(`${filepath}.mjs`)
? `${base}-${randomId()}.mjs`
: `${base}.mjs`
const tmpFilename = fs.existsSync(filepath + EXT)
? base + '-' + randomId() + EXT
: base + EXT

return writeAndImport(
await fs.readFile(filepath),
Expand All @@ -205,7 +203,7 @@ export async function importPath(
if (ext === '.md') {
return writeAndImport(
transformMarkdown(await fs.readFile(filepath)),
path.join(dir, base + '.mjs'),
path.join(dir, base + EXT),
origin
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export function preferLocalBin(
// }

export function quote(arg: string): string {
if (/^[a-z0-9/_.\-@:=]+$/i.test(arg) || arg === '') {
if (/^[\w/.\-@:=]+$/i.test(arg) || arg === '') {
return arg
}
return (
Expand All @@ -120,7 +120,7 @@ export function quote(arg: string): string {
}

export function quotePowerShell(arg: string): string {
if (/^[a-z0-9/_.\-]+$/i.test(arg) || arg === '') {
if (/^[\w/.\-]+$/i.test(arg) || arg === '') {
return arg
}
return `'` + arg.replace(/'/g, "''") + `'`
Expand Down

0 comments on commit 2af3de6

Please sign in to comment.