• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

pkgxdev / pkgx / 6605287914

22 Oct 2023 05:39PM UTC coverage: 97.311%. Remained the same
6605287914

push

github

mxcl
Have command not found handler sync

Sync is quick if they have done it recently. Let’s see how this feels.

Rationale: We add new pkgs all the time.

389 of 408 branches covered (0.0%)

2 of 5 new or added lines in 1 file covered. (40.0%)

5 existing lines in 1 file now uncovered.

1384 of 1414 relevant lines covered (97.88%)

137.81 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.78
/src/parse-args.ts
1
import { UsageError } from "./utils/error.ts"
2✔
2
import { Path, utils } from "pkgx"
2✔
3
const { flatmap } = utils
2✔
4

5
type Pkgs = {
6
  plus: string[]
7
  minus: string[]
8
}
9

10
export type Args = {
11
  flags: Flags
12
} & (
13
  {
14
    mode: 'x' | 'run'
15
    args: string[]
16
    unknown: string[]
17
    pkgs: Pkgs
18
  } | {
19
    mode: 'internal.use'
20
    pkgs: Pkgs
21
  } | {
22
    mode: 'env'
23
    pkgs: {
24
      plus: string[]
25
      minus: string[]
26
    }
27
  } | {
28
    mode: 'shellcode' | 'version' | 'help'
29
  } | {
30
    mode: 'integrate' | 'deintegrate'
31
    dryrun: boolean
32
  } | {
33
    mode: 'provider' | 'shell-completion'
34
    args: string[]
35
  } | {
36
    mode: 'internal.activate'
37
    dir: Path
38
  } | {
39
    mode: 'install'
40
    args: string[]
41
  }
42
)
43

44
interface Flags {
45
  sync: boolean
46
  update: boolean
47
  verbosity?: number
48
  keepGoing: boolean
49
}
50

51
export default function(input: string[]): Args {
2✔
52
  const it = input[Symbol.iterator]()
48✔
53
  const pkgs: Pkgs = { plus: [], minus: [] }
192✔
54
  const args: string[] = []
48✔
55
  const unknown: string[] = []
48✔
56
  const flags: Flags = {
48✔
57
    sync: false,
48✔
58
    update: false,
48✔
59
    keepGoing: false
48✔
60
  }
48✔
61
  let mode: string | undefined
48✔
62
  let dryrun: boolean | undefined
48✔
63

64
  switch (input[0]) {
48✔
65
  case 'deintegrate':
48✔
66
  case 'integrate':
48✔
67
  case 'install':
48✔
68
  case 'run':
48✔
69
    mode = input[0]
56✔
70
    it.next()  // consume the subcommand
56✔
71
  }
48✔
72

73
  for (const arg of it) {
48✔
74
    const [type, content] = parse(arg)
144✔
75

76
    switch (type) {
144✔
77
    case '+':
144✔
78
      pkgs.plus.push(content)
168✔
79
      break
168✔
80
    case '-':
144✔
81
      pkgs.minus.push(content)
146✔
82
      break
146✔
83
    case '--':
144✔
84
      switch (content) {
192✔
85
      case 'sync':
192✔
86
        flags.sync = true
194✔
87
        break
194✔
88
      case 'update':
192✔
89
        flags.update = true
194✔
90
        break
194✔
UNCOV
91
      case 'provides':
×
UNCOV
92
        if (mode) throw new UsageError({msg: 'multiple modes specified'})
×
93
        console.error("%cdeprecated: %cuse pkgx --provider instead", 'color: red', 'color: initial')
×
94
        mode = 'provider'
×
95
        break
×
96
      case 'shellcode':
192✔
97
      case 'integrate':
192✔
98
      case 'internal.activate':
192✔
99
      case 'help':
192✔
100
      case 'version':
192✔
101
      case 'provider':
192✔
102
      case 'shell-completion':
192✔
103
      case 'internal.use':
192✔
104
        if (mode) throw new UsageError({msg: 'multiple modes specified'})
664✔
105
        mode = content
232✔
106
        break
232✔
107
      case 'silent':
192✔
108
        flags.verbosity = -2
194✔
109
        break
194✔
110
      case 'quiet':
192✔
111
        flags.verbosity = -1
194✔
112
        break
194✔
113
      case 'dry-run':
192✔
114
        dryrun = true
196✔
115
        break
196✔
NEW
116
      case 'keep-going':
×
NEW
117
        flags.keepGoing = true
×
NEW
118
        break
×
119
      case '':
192✔
120
        // empty the main loop iterator
194✔
121
        for (const arg of it) unknown.push(arg)
194✔
122
        break
194✔
123
      default: {
394✔
124
        const match = content.match(/^verbose(=-?\d+)?$/)
202✔
125
        if (match) {
202✔
126
          flags.verbosity = flatmap(match[1], n => parseInt(n.slice(1))!) ?? 1
210✔
127
        } else {
202✔
128
          throw new UsageError(arg)
204✔
129
        }
204✔
130
      }}
394✔
131
      break
230✔
132
    default:
144✔
133
      /// unrecognized args means the start of the runner args
162✔
134
      args.push(arg)
162✔
135
      for (const arg of it) args.push(arg)
162✔
136
    }
162✔
137
  }
162✔
138

139
  if (dryrun !== undefined && !(mode == 'integrate' || mode == 'deintegrate')) {
48✔
140
    throw new UsageError({msg: '--dry-run cannot be specified with this mode'})
150✔
141
  }
50✔
142

143
  switch (mode) {
78✔
144
  case undefined:
48✔
145
    if (args.length + unknown.length) {
64✔
146
      return { mode: 'x', flags, pkgs, args, unknown }
490✔
147
    } else {
64✔
148
      return { mode: 'env', flags, pkgs }
370✔
149
    }
74✔
150
  case 'internal.use':
48✔
151
    return { mode, flags, pkgs }
250✔
152
  case 'provider':
48✔
153
  case 'shell-completion':
48✔
154
    return { mode, flags, args }
250✔
155
  case 'internal.activate':
48✔
156
    return { mode, flags, dir: new Path(args[0]) }
250✔
157
  case 'install':
48✔
158
    return { mode, flags, args }
250✔
159
  case 'integrate':
48✔
160
  case 'deintegrate':
48✔
161
    dryrun ??= false
54✔
162
    return { mode, dryrun, flags }
270✔
UNCOV
163
  default:
×
UNCOV
164
    // deno-lint-ignore no-explicit-any
×
UNCOV
165
    return { mode: mode as any, flags }
×
166
  }
48✔
167
}
48✔
168

169

170
//////////////////////// utils
2✔
171

172
function parse(arg: string): ['+', string] | ['--', string] | ['-', string] | [undefined, string] {
98✔
173
  switch (arg[0]) {
98✔
174
  case '+': {
222✔
175
    const content = arg.slice(1)
124✔
176
    if (!content) throw new UsageError(arg)
124✔
177
    return ['+', content]
592✔
178
  }
148✔
179
  case '-':
98✔
180
    if (arg[1] == '-') {
150✔
181
      return ['--', arg.slice(2)]
792✔
182
    } else {
150✔
183
      const content = arg.slice(1)
154✔
184
      if (!content) throw new UsageError(arg)
154✔
185
      return ['-', content]
624✔
186
    }
156✔
187
  default:
98✔
188
    return [undefined, arg]
464✔
189
  }
98✔
190
}
98✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc