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

gturi / nca / 8277672099

14 Mar 2024 08:32AM UTC coverage: 86.091% (+0.1%) from 85.979%
8277672099

push

github

web-flow
Merge pull request #213 from gturi/feature/nca-alias-command

Feature/nca alias command

221 of 316 branches covered (69.94%)

Branch coverage included in aggregate %.

598 of 661 new or added lines in 62 files covered. (90.47%)

1 existing line in 1 file now uncovered.

1116 of 1237 relevant lines covered (90.22%)

1211.08 hits per line

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

91.3
/src/command/alias/completion-alias-command.ts
1
import yargs from "yargs";
2
import { PositionalArgument } from '../../model/api/positional-argument';
3
import { PositionalArgumentType } from '../../model/api/positional-argument-type';
161✔
4
import { AnyObj } from "../../util/custom-types";
5
import { YargsUtils } from '../../util/yargs-utils';
161✔
6
import { PackageJsonLoader } from '../../loader/package-json-loader';
161✔
7
import { ProcessArgumentUtils } from "../../util/process-arguments-utils";
161✔
8
import { NcaCommandTemplate } from "../../model/internal/nca-command-template";
161✔
9

10
export class CompletionAliasCommand extends NcaCommandTemplate {
161✔
11

12
  override getCommandName(): string {
13
    return YargsUtils.getCommand('completion', this.getPositionalArguments());
161✔
14
  }
15

16
  override getCommandDescription(): string {
17
    return 'get completion for a global alias for a nca command';
161✔
18
  }
19

20
  override getPositionalArguments(): PositionalArgument[] {
21
    const aliasArgument: PositionalArgument = {
322✔
22
      name: 'aliasName',
23
      description: 'alias to get completion for',
24
      type: PositionalArgumentType.String,
25
      required: true
26
    }
27
    return [aliasArgument];
322✔
28
  }
29

30
  override getHandler<T = AnyObj>(args: yargs.ArgumentsCamelCase<T>): void {
31
    const aliasName = args.aliasName as string;
3✔
32

33
    const packageJsonLoader = new PackageJsonLoader();
3✔
34
    const aliasCodePath = packageJsonLoader.getAliasCodePath(aliasName);
3✔
35

36
    if (aliasCodePath === null) {
3!
NEW
37
      throw new Error(`Alias '${aliasName}' not found`);
×
38
    }
39

40
    // eslint-disable-next-line @typescript-eslint/no-var-requires
41
    const { commandArray } = require(aliasCodePath);
3✔
42

43
    const completion = this.getCompletion(aliasName, commandArray);
3✔
44
    console.log(completion);
3✔
45
  }
46

47
  private getCompletion(aliasName: string, commandArray: string[]): string {
48
    const aliasCompletionFunction = `_nca_${aliasName}_yargs_completions`;
3✔
49
    const inputArgs = ProcessArgumentUtils.sanitizeCommandArray(commandArray).join(' ');
3✔
50
    return [
3✔
51
      `# ${aliasName} completion`,
52
      `${aliasCompletionFunction}()`,
53
      `{`,
54
      `    _nca_yargs_completions ${inputArgs}`,
55
      ``,
56
      `    return 0`,
57
      `}`,
58
      `complete -o bashdefault -o default -F ${aliasCompletionFunction} ${aliasName}`
59
    ].join('\n') + '\n';
60
  }
61
}
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

© 2025 Coveralls, Inc