Skip to content

Commit 5f5506c

Browse files
authored
feat: Command to print project cache directory (#306)
1 parent 4afad32 commit 5f5506c

File tree

4 files changed

+86
-75
lines changed

4 files changed

+86
-75
lines changed

README.md

Lines changed: 58 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ Click [here](./docs/PROJECT-CONFIG.md) for an in-depth overview of the project c
9898
* [`velocitas component remove ID`](#velocitas-component-remove-id)
9999
* [`velocitas create`](#velocitas-create)
100100
* [`velocitas exec COMPONENT REF [ARGS...]`](#velocitas-exec-component-ref-args)
101-
* [`velocitas help [COMMANDS]`](#velocitas-help-commands)
102101
* [`velocitas init`](#velocitas-init)
103102
* [`velocitas package [NAME]`](#velocitas-package-name)
104103
* [`velocitas sync`](#velocitas-sync)
@@ -127,11 +126,14 @@ Get the complete cache contents as JSON string or the value of a single key.
127126

128127
```
129128
USAGE
130-
$ velocitas cache get [KEY]
129+
$ velocitas cache get [KEY] [-p]
131130
132131
ARGUMENTS
133132
KEY The key of a single cache entry to get.
134133
134+
FLAGS
135+
-p, --path Print the cache path instead of the contents.
136+
135137
DESCRIPTION
136138
Get the complete cache contents as JSON string or the value of a single key.
137139
@@ -141,6 +143,9 @@ EXAMPLES
141143
142144
$ velocitas cache get foo
143145
bar
146+
147+
$ velocitas cache get --path
148+
/home/user/.velocitas/projects/...
144149
```
145150

146151
_See code: [src/commands/cache/get.ts](src/commands/cache/get.ts)_
@@ -216,7 +221,7 @@ USAGE
216221
$ velocitas component remove ID
217222
218223
ARGUMENTS
219-
ID ID of the component to add
224+
ID ID of the component to remove
220225
221226
DESCRIPTION
222227
Remove project components.
@@ -233,7 +238,7 @@ Create a new Velocitas Vehicle App project.
233238

234239
```
235240
USAGE
236-
$ velocitas create [-n <value>] [-c <value>] [-e <value>] [-i <value>]
241+
$ velocitas create [-n <value>] [-c <value>] [-e <value>] [-i <value>...]
237242
238243
FLAGS
239244
-c, --core=<value> Which core to use for the project.
@@ -257,13 +262,13 @@ Executes a script contained in one of your installed components.
257262

258263
```
259264
USAGE
260-
$ velocitas exec COMPONENT REF [ARGS...] [-v]
265+
$ velocitas exec COMPONENT... REF... [ARGS......] [-v]
261266
262267
ARGUMENTS
263-
COMPONENT The component which provides the program
264-
REF Reference to the ID of the program to execute
265-
ARGS... Args for the executed program. All arguments and flags provided after the ref are forwarded to the invoked
266-
program.
268+
COMPONENT... The component which provides the program
269+
REF... Reference to the ID of the program to execute
270+
ARGS...... Args for the executed program. All arguments and flags provided after the ref are forwarded to the
271+
invoked program.
267272
268273
FLAGS
269274
-v, --verbose Enable verbose logging. The flag may be provided before or in between the 2 positional arguments of
@@ -275,69 +280,49 @@ DESCRIPTION
275280
276281
EXAMPLES
277282
$ velocitas exec runtime-local up
278-
Executing script...
283+
Executing script...
279284
```
280285

281286
_See code: [src/commands/exec/index.ts](src/commands/exec/index.ts)_
282287

283-
## `velocitas help [COMMANDS]`
284-
285-
Display help for velocitas.
286-
287-
```
288-
USAGE
289-
$ velocitas help [COMMANDS] [-n]
290-
291-
ARGUMENTS
292-
COMMANDS Command to show help for.
293-
294-
FLAGS
295-
-n, --nested-commands Include all nested commands in the output.
296-
297-
DESCRIPTION
298-
Display help for velocitas.
299-
```
300-
301-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.20/src/commands/help.ts)_
302-
303288
## `velocitas init`
304289

305290
Initializes Velocitas Vehicle App
306291

307292
```
308293
USAGE
309-
$ velocitas init [-p PACKAGE] [-s VERSION_SPECIFIER] [-v] [-f] [--no-hooks]
294+
$ velocitas init [-v] [-f] [--no-hooks] [-s <value> -p <value>]
310295
311296
FLAGS
312-
-p, --package Package to initialize
313-
-s, --specifier Version specifier for the specified package
314-
-f, --force Force (re-)download packages
315-
-v, --verbose Enable verbose logging
316-
--no-hooks Skip post init hooks
297+
-f, --force Force (re-)download packages
298+
-p, --package=<value> Package to initialize
299+
-s, --specifier=<value> Version specifier for the specified package
300+
-v, --verbose Enable verbose logging
301+
--no-hooks Skip post init hooks
317302
318303
DESCRIPTION
319304
Initializes Velocitas Vehicle App
320305
321306
EXAMPLES
322307
$ velocitas init
323-
Initializing Velocitas packages ...
324-
... Downloading package: 'pkg-velocitas-main:vx.x.x'
325-
... Downloading package: 'devenv-devcontainer-setup:vx.x.x'
326-
... Downloading package: 'devenv-runtimes:vx.x.x'
327-
... Downloading package: 'devenv-github-templates:vx.x.x'
328-
... Downloading package: 'devenv-github-workflows:vx.x.x'
308+
Initializing Velocitas packages ...
309+
... Downloading package: 'pkg-velocitas-main:vx.x.x'
310+
... Downloading package: 'devenv-devcontainer-setup:vx.x.x'
311+
... Downloading package: 'devenv-runtimes:vx.x.x'
312+
... Downloading package: 'devenv-github-templates:vx.x.x'
313+
... Downloading package: 'devenv-github-workflows:vx.x.x'
329314
330315
$ velocitas init -p devenv-runtimes
331-
Initializing Velocitas packages ...
332-
... Package 'devenv-runtimes:vx.x.x' added to .velocitas.json
333-
... Downloading package: 'devenv-runtimes:vx.x.x'
334-
... > Running post init hook for ...'
316+
Initializing Velocitas packages ...
317+
... Package 'devenv-runtimes:vx.x.x' added to .velocitas.json
318+
... Downloading package: 'devenv-runtimes:vx.x.x'
319+
... > Running post init hook for ...'
335320
336321
$ velocitas init -p devenv-runtimes -s v3.0.0
337-
Initializing Velocitas packages ...
338-
... Package 'devenv-runtimes:v3.0.0' added to .velocitas.json
339-
... Downloading package: 'devenv-runtimes:v3.0.0'
340-
... > Running post init hook for ...
322+
Initializing Velocitas packages ...
323+
... Package 'devenv-runtimes:v3.0.0' added to .velocitas.json
324+
... Downloading package: 'devenv-runtimes:v3.0.0'
325+
... > Running post init hook for ...
341326
```
342327

343328
_See code: [src/commands/init/index.ts](src/commands/init/index.ts)_
@@ -361,18 +346,18 @@ DESCRIPTION
361346
362347
EXAMPLES
363348
$ velocitas package devenv-runtimes
364-
devenv-runtimes:
365-
version: v3.0.0
366-
components:
367-
- id: runtime-local
368-
variables:
369-
- runtimeFilePath:
370-
type: string
371-
description: "Path to the file describing your custom runtime configuration."
372-
required: false
373-
default: runtime.json
374-
$ velocitas package --get-path devenv-runtimes
375-
/home/vscode/.velocitas/packages/devenv-runtimes/v3.0.0
349+
devenv-runtimes:
350+
version: v3.0.0
351+
components:
352+
- id: runtime-local
353+
variables:
354+
- runtimeFilePath:
355+
type: string
356+
description: "Path to the file describing your custom runtime configuration."
357+
required: false
358+
default: runtime.json
359+
$ velocitas package --get-path devenv-runtimes
360+
/home/vscode/.velocitas/packages/devenv-runtimes/v3.0.0
376361
```
377362

378363
_See code: [src/commands/package/index.ts](src/commands/package/index.ts)_
@@ -406,22 +391,23 @@ USAGE
406391
$ velocitas upgrade [--dry-run] [--ignore-bounds] [--init] [-v]
407392
408393
FLAGS
409-
-v, --verbose Enable verbose logging
410-
--dry-run Check which packages can be upgraded
411-
--ignore-bounds Ignores specified version ranges and will result in upgrading to the latest available semantic version
412-
--init Initializes components after upgrading them.
394+
-v, --verbose Enable verbose logging
395+
--dry-run Check which packages can be upgraded
396+
--ignore-bounds Ignores specified version ranges and will result in upgrading to the latest available semantic
397+
version
398+
--init Initializes components after upgrading them
413399
414400
DESCRIPTION
415401
Updates Velocitas components.
416402
417403
EXAMPLES
418404
$ velocitas upgrade
419-
Checking .velocitas.json for updates!
420-
... pkg-velocitas-main:vx.x.x → up to date!
421-
... devenv-devcontainer-setup:vx.x.x → up to date!
422-
... devenv-runtimes:vx.x.x → vx.x.x
423-
... devenv-github-templates:vx.x.x → up to date!
424-
... devenv-github-workflows:vx.x.x → up to date!
405+
Checking .velocitas.json for updates!
406+
... pkg-velocitas-main:vx.x.x → up to date!
407+
... devenv-devcontainer-setup:vx.x.x → up to date!
408+
... devenv-runtimes:vx.x.x → vx.x.x
409+
... devenv-github-templates:vx.x.x → up to date!
410+
... devenv-github-workflows:vx.x.x → up to date!
425411
```
426412

427413
_See code: [src/commands/upgrade/index.ts](src/commands/upgrade/index.ts)_

src/commands/cache/get.ts

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
//
1313
// SPDX-License-Identifier: Apache-2.0
1414

15-
import { Args, Command } from '@oclif/core';
15+
import { Args, Command, Flags } from '@oclif/core';
1616
import { mapReplacer } from '../../modules/helpers';
1717
import { ProjectCache } from '../../modules/project-cache';
1818
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
@@ -25,19 +25,35 @@ export default class Get extends Command {
2525
{"foo":"bar"}`,
2626
`$ velocitas cache get foo
2727
bar`,
28+
`$ velocitas cache get --path
29+
/home/user/.velocitas/projects/...`,
2830
];
2931

32+
static flags = {
33+
path: Flags.boolean({
34+
description: 'Print the cache path instead of the contents.',
35+
aliases: ['path'],
36+
char: 'p',
37+
default: false,
38+
}),
39+
};
40+
3041
static args = {
3142
key: Args.string({ description: 'The key of a single cache entry to get.', required: false }),
3243
};
3344

3445
async run(): Promise<void> {
35-
const { args } = await this.parse(Get);
46+
const { args, flags } = await this.parse(Get);
3647

3748
// although we are not reading the project config, we want to
3849
// ensure the command is run in a project directory only.
3950
ProjectConfigIO.read(`v${this.config.version}`);
4051

52+
if (flags.path) {
53+
this.log(ProjectCache.getCacheDir());
54+
return;
55+
}
56+
4157
const cache = ProjectCache.read();
4258

4359
let output = JSON.stringify(cache.raw(), mapReplacer);

src/commands/package/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
// SPDX-License-Identifier: Apache-2.0
1414

1515
import { Args, Command, Flags } from '@oclif/core';
16-
import { join } from 'node:path';
1716
import { PackageConfig } from '../../modules/package';
1817
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
1918

test/commands/cache/cache.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
// SPDX-License-Identifier: Apache-2.0
1414

1515
import { expect, test } from '@oclif/test';
16+
import { getVelocitasRoot } from '../../../src/modules/package';
1617
import { getCacheData } from '../../helpers/cache';
1718
import { mockFolders } from '../../utils/mockfs';
1819

@@ -35,6 +36,15 @@ describe('cache', () => {
3536
expect(ctx.stdout).to.equal('myValue\n');
3637
});
3738

39+
test.do(() => {
40+
mockFolders({ velocitasConfig: true });
41+
})
42+
.stdout()
43+
.command(['cache get', '--path'])
44+
.it('prints the cache path', (ctx) => {
45+
expect(ctx.stdout.trim().startsWith(`${getVelocitasRoot()}/projects`)).to.be.true;
46+
});
47+
3848
test.do(() => {
3949
mockFolders({ velocitasConfig: true });
4050
})

0 commit comments

Comments
 (0)