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

RauliL / varasto / 20749563837

06 Jan 2026 01:21PM UTC coverage: 91.283% (-0.08%) from 91.361%
20749563837

push

github

web-flow
Merge pull request #150 from RauliL/eslint-update

Update ESLint and bunch of other dependencies

673 of 718 branches covered (93.73%)

Branch coverage included in aggregate %.

41 of 47 new or added lines in 15 files covered. (87.23%)

1 existing line in 1 file now uncovered.

2322 of 2563 relevant lines covered (90.6%)

13.71 hits per line

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

0.96
/packages/cli/src/command.ts
1
import { Storage } from '@varasto/storage';
3✔
2
import JSON5 from 'json5';
×
3
import { colorize } from 'json-colorizer';
×
4

5
import { tokenize } from './tokenizer';
×
6

7
export type CommandDefinition = {
8
  description: string;
9
  args?: string[];
10
  callback: (storage: Storage, args: string[]) => Promise<void>;
11
};
12

NEW
13
const renderValue = (value: string | object): string =>
×
NEW
14
  colorize(value, { indent: 2 });
×
15

16
export const renderUsage = (command: CommandDefinition): string =>
×
17
  command.args?.map((arg) => `<${arg}>`).join(' ') ?? '';
×
18

19
const commands: Readonly<Record<string, CommandDefinition>> = {
×
20
  quit: {
×
21
    description: 'Exits the command line interface.',
×
22
    async callback() {
×
23
      process.exit(0);
×
24
    },
×
25
  },
×
26
  help: {
×
27
    description: 'Displays information about an command.',
×
28
    args: ['command'],
×
29
    async callback(storage, [command]) {
×
30
      const definition = commands[command];
×
31

32
      if (definition) {
×
33
        console.log(`${command} ${renderUsage(definition)}`);
×
34
        console.log(definition.description);
×
35
      } else {
×
36
        throw new Error(`Unknown command: ${command}`);
×
37
      }
×
38
    },
×
39
  },
×
40
  list: {
×
41
    description: 'Lists all entries from an namespace.',
×
42
    args: ['namespace'],
×
43
    async callback(storage, [namespace]) {
×
44
      for await (const [key, value] of storage.entries(namespace)) {
×
NEW
45
        console.log(renderValue({ [key]: value }));
×
46
      }
×
47
    },
×
48
  },
×
49
  keys: {
×
50
    description: 'Lists keys of all entries from an namespace.',
×
51
    args: ['namespace'],
×
52
    async callback(storage, [namespace]) {
×
53
      for await (const key of storage.keys(namespace)) {
×
54
        console.log(key);
×
55
      }
×
56
    },
×
57
  },
×
58
  get: {
×
59
    description: 'Retrieves an entry from an namespace.',
×
60
    args: ['namespace', 'key'],
×
61
    async callback(storage, [namespace, key]) {
×
62
      const value = await storage.get(namespace, key);
×
63

64
      if (value === undefined) {
×
65
        console.error('Entry does not exist.');
×
66
      } else {
×
67
        console.log(renderValue(value));
×
68
      }
×
69
    },
×
70
  },
×
71
  set: {
×
72
    description: 'Inserts an entry to namespace.',
×
73
    args: ['namespace', 'key', 'value'],
×
74
    async callback(storage, [namespace, key, value]) {
×
75
      await storage.set(namespace, key, JSON5.parse(value));
×
76
    },
×
77
  },
×
78
  update: {
×
79
    description: 'Patches an already existing entry in namespace.',
×
80
    args: ['namespace', 'key', 'value'],
×
81
    async callback(storage, [namespace, key, value]) {
×
82
      console.log(
×
83
        renderValue(await storage.update(namespace, key, JSON5.parse(value)))
×
84
      );
×
85
    },
×
86
  },
×
87
  delete: {
×
88
    description: 'Deletes an entry from namespace.',
×
89
    args: ['namespace', 'key'],
×
90
    async callback(storage, [namespace, key]) {
×
91
      if (!(await storage.delete(namespace, key))) {
×
92
        console.error('Item does not exist.');
×
93
      }
×
94
    },
×
95
  },
×
96
};
×
97

98
export const commandNames: Readonly<string[]> = Object.keys(commands).sort();
×
99

100
export const runCommand = async (
×
101
  storage: Storage,
×
102
  input: string
×
103
): Promise<void> => {
×
104
  const args = tokenize(input);
×
105
  let command: CommandDefinition;
×
106

UNCOV
107
  if (args.length === 0) {
×
108
    return;
×
109
  } else if (!(command = commands[args[0]])) {
×
110
    throw new Error(`Unknown command: ${args[0]}`);
×
111
  }
×
112

NEW
113
  const arity = command.args?.length ?? 0;
×
114

115
  if (args.length - 1 < arity) {
×
116
    throw new Error(`Missing arguments for command ${args[0]}`);
×
117
  } else if (args.length - 1 > arity) {
×
118
    throw new Error(`Too many arguments for command ${args[0]}`);
×
119
  }
×
120

121
  await command.callback(storage, args.slice(1));
×
122
};
×
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