@gutenye/script.js 2.7.1 → 2.7.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gutenye/script.js",
3
- "version": "2.7.1",
3
+ "version": "2.7.3",
4
4
  "description": "Write shell scripts in JavaScript",
5
5
  "keywords": [
6
6
  "shell",
package/src/Command.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import { Argument } from './Argument'
2
- import { Option } from './Option'
3
2
  import { installCompletion } from './completion'
3
+ import { Option } from './Option'
4
4
  import { parseArgv } from './parseArgv'
5
5
 
6
6
  export class Command {
@@ -1,6 +1,10 @@
1
1
  function _setup_ake_complete
2
2
  set cmd $argv[1]
3
- set suffix $argv[2]
3
+ if set -q argv[2]
4
+ set suffix $argv[2]
5
+ else
6
+ set suffix ''
7
+ end
4
8
  complete --erase $cmd$suffix
5
9
  complete --command $cmd$suffix --no-files --arguments "(_ake_complete $suffix)"
6
10
  end
package/src/ake/shared.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import fsSync from 'node:fs'
2
- import path from 'node:path'
3
2
  import os from 'node:os'
3
+ import path from 'node:path'
4
4
  import fs from '../utils/fs'
5
5
 
6
6
  const HOME = os.homedir()
package/src/completion.ts CHANGED
@@ -2,8 +2,8 @@ import fsSync from 'node:fs'
2
2
  import os from 'node:os'
3
3
  import path from 'node:path'
4
4
  import * as yaml from 'yaml'
5
- import type { Command } from './Command'
6
5
  import { getAkeSuffix, getCompletionName } from './ake/shared'
6
+ import type { Command } from './Command'
7
7
 
8
8
  export type CompletionValue = string[] | (() => string[])
9
9
 
@@ -60,11 +60,12 @@ export function buildSpec(command: Command): CarapaceSpec {
60
60
  for (const opt of command.options) {
61
61
  spec.flags = spec.flags || {}
62
62
  let flag = [opt.short, opt.long].filter(Boolean).join(', ')
63
+ const values = resolveCompletion(opt.completion)
63
64
  if (opt.required) flag += '='
64
65
  else if (opt.optional) flag += '=?'
66
+ else if (values.length > 0) flag += '='
65
67
  spec.flags[flag] = opt.description
66
68
 
67
- const values = resolveCompletion(opt.completion)
68
69
  if (values.length > 0) {
69
70
  completion.flag = completion.flag || {}
70
71
  const key = opt.long?.replace(/^--/, '') || opt.attributeName
@@ -1,5 +1,7 @@
1
- export function exitWithError(message: string, help?: string) {
1
+ export function exitWithError(message: string, help?: string): never {
2
2
  console.error(`\nError: ${message}`)
3
- if (help) console.log(`\n${help}`)
3
+ if (help) {
4
+ console.log(`\n${help}`)
5
+ }
4
6
  process.exit(1)
5
7
  }