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

stackpress / lib / 15067526568

16 May 2025 11:34AM UTC coverage: 79.037% (-6.1%) from 85.102%
15067526568

push

github

cblanquera
terminal tests and fixes

482 of 670 branches covered (71.94%)

Branch coverage included in aggregate %.

1 of 1 new or added line in 1 file covered. (100.0%)

51 existing lines in 10 files now uncovered.

913 of 1095 relevant lines covered (83.38%)

27.57 hits per line

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

95.77
/src/data/processors/ArgString.ts
1
//data
2
import type Nest from '../Nest.js';
3

4
export default class ArgString {
5
  /**
6
   * The main nest
7
   */
8
  public nest: Nest;
9

10
  /**
11
   * Sets the nest 
12
   */
13
  constructor(nest: Nest) {
14
    this.nest = nest;
163✔
15
  }
16

17
  /**
18
   * Creates the name space given the space
19
   * and sets the value to that name space
20
   */
21
  set(argv: string|string[], skip = 0): Nest {
20✔
22
    if (typeof argv === 'string') {
36✔
23
      let buffer = '';
12✔
24
      let quote: string|null = null;
12✔
25
      const args: string[] = [];
12✔
26
      for (let i = 0; i < argv.length; i++) {
12✔
27
        const char = argv[i];
555✔
28
        //if we are in a quote
29
        if (quote) {
555✔
30
          //if we are closing the quote
31
          if (char === quote) {
7✔
32
            quote = null;
1✔
33
            continue;
1✔
34
          }
35
          //add to buffer
36
          buffer += char;
6✔
37
          continue;
6✔
38
        }
39
        //if we are not in a quote
40
        if (char === '"' || char === "'") {
548✔
41
          //set the quote
42
          quote = char;
1✔
43
          continue;
1✔
44
        }
45
        //if we are here, then no quotes
46
        if (char === ' ') {
547✔
47
          //push the buffer to args
48
          args.push(buffer);
65✔
49
          buffer = '';
65✔
50
          continue;
65✔
51
        }
52
        //add to buffer
53
        buffer += char;
482✔
54
      }
55
      //push the last buffer to args
56
      if (buffer) {
12!
57
        args.push(buffer);
12✔
58
      }
59
      return this.set(args, skip);
12✔
60
    }
61
    // [ '-xyz', '--foo=bar', '--foo', 'bar' ]
62
    // [ '-xyz', '--foo[]', 'bar', '--foo[bar]', 'bar' ]
63
    // [ '--foo[bar]=a b c', '--foo[]=a b c', '--foo[bar][]=a b c' ]
64
    const args = argv.slice(skip);
24✔
65

66
    if (args.length < 1) {
24!
UNCOV
67
      return this.nest;
×
68
    }
69

70
    //this will hold all the key/value pairs per string
71
    const query: string[] = [];
24✔
72
    //key tmp buffer
73
    let index = 0, key: string|number|null = null;
24✔
74
    for (let i = 0; i < args.length; i++) {
24✔
75
      const arg = args[i];
174✔
76
      //if key is set
77
      if (key) {
174✔
78
        //take the arg as the value (no matter what it is)
79
        query.push(`${key}=${arg}`);
76✔
80
        //reset the key
81
        key = null;
76✔
82
        continue;
76✔
83
      }
84
      //if we are here, then no key yet...
85
      if (arg.startsWith('--')) {
98✔
86
        key = arg.substring(2);
78✔
87
        //key can be: '', 'x', 'xy'
88
        continue;
78✔
89
      }
90
      //if flag
91
      if (arg.startsWith('-')) {
20✔
92
        // [x, y, z]
93
        let flags = arg.substring(1);
7✔
94
        flags.split('').forEach(flag => query.push(`${flag}=true`));
9✔
95
        continue;
7✔
96
      }
97
      //if we are here, then no - nor -- nor name=value
98
      query.push(`${index++}=${arg}`);
13✔
99
    }
100

101
    if (query.length > 0) {
24✔
102
      this.nest.withQuery.set(query.join('&'));
22✔
103
    }
104
    
105
    return this.nest;
24✔
106
  }
107
}
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