Skip to content

Commit

Permalink
feat: Command to print project cache directory (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
doosuu authored Jul 31, 2024
1 parent 4afad32 commit 5f5506c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 75 deletions.
130 changes: 58 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ Click [here](./docs/PROJECT-CONFIG.md) for an in-depth overview of the project c
* [`velocitas component remove ID`](#velocitas-component-remove-id)
* [`velocitas create`](#velocitas-create)
* [`velocitas exec COMPONENT REF [ARGS...]`](#velocitas-exec-component-ref-args)
* [`velocitas help [COMMANDS]`](#velocitas-help-commands)
* [`velocitas init`](#velocitas-init)
* [`velocitas package [NAME]`](#velocitas-package-name)
* [`velocitas sync`](#velocitas-sync)
Expand Down Expand Up @@ -127,11 +126,14 @@ Get the complete cache contents as JSON string or the value of a single key.

```
USAGE
$ velocitas cache get [KEY]
$ velocitas cache get [KEY] [-p]
ARGUMENTS
KEY The key of a single cache entry to get.
FLAGS
-p, --path Print the cache path instead of the contents.
DESCRIPTION
Get the complete cache contents as JSON string or the value of a single key.
Expand All @@ -141,6 +143,9 @@ EXAMPLES
$ velocitas cache get foo
bar
$ velocitas cache get --path
/home/user/.velocitas/projects/...
```

_See code: [src/commands/cache/get.ts](src/commands/cache/get.ts)_
Expand Down Expand Up @@ -216,7 +221,7 @@ USAGE
$ velocitas component remove ID
ARGUMENTS
ID ID of the component to add
ID ID of the component to remove
DESCRIPTION
Remove project components.
Expand All @@ -233,7 +238,7 @@ Create a new Velocitas Vehicle App project.

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

```
USAGE
$ velocitas exec COMPONENT REF [ARGS...] [-v]
$ velocitas exec COMPONENT... REF... [ARGS......] [-v]
ARGUMENTS
COMPONENT The component which provides the program
REF Reference to the ID of the program to execute
ARGS... Args for the executed program. All arguments and flags provided after the ref are forwarded to the invoked
program.
COMPONENT... The component which provides the program
REF... Reference to the ID of the program to execute
ARGS...... Args for the executed program. All arguments and flags provided after the ref are forwarded to the
invoked program.
FLAGS
-v, --verbose Enable verbose logging. The flag may be provided before or in between the 2 positional arguments of
Expand All @@ -275,69 +280,49 @@ DESCRIPTION
EXAMPLES
$ velocitas exec runtime-local up
Executing script...
Executing script...
```

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

## `velocitas help [COMMANDS]`

Display help for velocitas.

```
USAGE
$ velocitas help [COMMANDS] [-n]
ARGUMENTS
COMMANDS Command to show help for.
FLAGS
-n, --nested-commands Include all nested commands in the output.
DESCRIPTION
Display help for velocitas.
```

_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v5.2.20/src/commands/help.ts)_

## `velocitas init`

Initializes Velocitas Vehicle App

```
USAGE
$ velocitas init [-p PACKAGE] [-s VERSION_SPECIFIER] [-v] [-f] [--no-hooks]
$ velocitas init [-v] [-f] [--no-hooks] [-s <value> -p <value>]
FLAGS
-p, --package Package to initialize
-s, --specifier Version specifier for the specified package
-f, --force Force (re-)download packages
-v, --verbose Enable verbose logging
--no-hooks Skip post init hooks
-f, --force Force (re-)download packages
-p, --package=<value> Package to initialize
-s, --specifier=<value> Version specifier for the specified package
-v, --verbose Enable verbose logging
--no-hooks Skip post init hooks
DESCRIPTION
Initializes Velocitas Vehicle App
EXAMPLES
$ velocitas init
Initializing Velocitas packages ...
... Downloading package: 'pkg-velocitas-main:vx.x.x'
... Downloading package: 'devenv-devcontainer-setup:vx.x.x'
... Downloading package: 'devenv-runtimes:vx.x.x'
... Downloading package: 'devenv-github-templates:vx.x.x'
... Downloading package: 'devenv-github-workflows:vx.x.x'
Initializing Velocitas packages ...
... Downloading package: 'pkg-velocitas-main:vx.x.x'
... Downloading package: 'devenv-devcontainer-setup:vx.x.x'
... Downloading package: 'devenv-runtimes:vx.x.x'
... Downloading package: 'devenv-github-templates:vx.x.x'
... Downloading package: 'devenv-github-workflows:vx.x.x'
$ velocitas init -p devenv-runtimes
Initializing Velocitas packages ...
... Package 'devenv-runtimes:vx.x.x' added to .velocitas.json
... Downloading package: 'devenv-runtimes:vx.x.x'
... > Running post init hook for ...'
Initializing Velocitas packages ...
... Package 'devenv-runtimes:vx.x.x' added to .velocitas.json
... Downloading package: 'devenv-runtimes:vx.x.x'
... > Running post init hook for ...'
$ velocitas init -p devenv-runtimes -s v3.0.0
Initializing Velocitas packages ...
... Package 'devenv-runtimes:v3.0.0' added to .velocitas.json
... Downloading package: 'devenv-runtimes:v3.0.0'
... > Running post init hook for ...
Initializing Velocitas packages ...
... Package 'devenv-runtimes:v3.0.0' added to .velocitas.json
... Downloading package: 'devenv-runtimes:v3.0.0'
... > Running post init hook for ...
```

_See code: [src/commands/init/index.ts](src/commands/init/index.ts)_
Expand All @@ -361,18 +346,18 @@ DESCRIPTION
EXAMPLES
$ velocitas package devenv-runtimes
devenv-runtimes:
version: v3.0.0
components:
- id: runtime-local
variables:
- runtimeFilePath:
type: string
description: "Path to the file describing your custom runtime configuration."
required: false
default: runtime.json
$ velocitas package --get-path devenv-runtimes
/home/vscode/.velocitas/packages/devenv-runtimes/v3.0.0
devenv-runtimes:
version: v3.0.0
components:
- id: runtime-local
variables:
- runtimeFilePath:
type: string
description: "Path to the file describing your custom runtime configuration."
required: false
default: runtime.json
$ velocitas package --get-path devenv-runtimes
/home/vscode/.velocitas/packages/devenv-runtimes/v3.0.0
```

_See code: [src/commands/package/index.ts](src/commands/package/index.ts)_
Expand Down Expand Up @@ -406,22 +391,23 @@ USAGE
$ velocitas upgrade [--dry-run] [--ignore-bounds] [--init] [-v]
FLAGS
-v, --verbose Enable verbose logging
--dry-run Check which packages can be upgraded
--ignore-bounds Ignores specified version ranges and will result in upgrading to the latest available semantic version
--init Initializes components after upgrading them.
-v, --verbose Enable verbose logging
--dry-run Check which packages can be upgraded
--ignore-bounds Ignores specified version ranges and will result in upgrading to the latest available semantic
version
--init Initializes components after upgrading them
DESCRIPTION
Updates Velocitas components.
EXAMPLES
$ velocitas upgrade
Checking .velocitas.json for updates!
... pkg-velocitas-main:vx.x.x → up to date!
... devenv-devcontainer-setup:vx.x.x → up to date!
... devenv-runtimes:vx.x.x → vx.x.x
... devenv-github-templates:vx.x.x → up to date!
... devenv-github-workflows:vx.x.x → up to date!
Checking .velocitas.json for updates!
... pkg-velocitas-main:vx.x.x → up to date!
... devenv-devcontainer-setup:vx.x.x → up to date!
... devenv-runtimes:vx.x.x → vx.x.x
... devenv-github-templates:vx.x.x → up to date!
... devenv-github-workflows:vx.x.x → up to date!
```

_See code: [src/commands/upgrade/index.ts](src/commands/upgrade/index.ts)_
Expand Down
20 changes: 18 additions & 2 deletions src/commands/cache/get.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//
// SPDX-License-Identifier: Apache-2.0

import { Args, Command } from '@oclif/core';
import { Args, Command, Flags } from '@oclif/core';
import { mapReplacer } from '../../modules/helpers';
import { ProjectCache } from '../../modules/project-cache';
import { ProjectConfigIO } from '../../modules/projectConfig/projectConfigIO';
Expand All @@ -25,19 +25,35 @@ export default class Get extends Command {
{"foo":"bar"}`,
`$ velocitas cache get foo
bar`,
`$ velocitas cache get --path
/home/user/.velocitas/projects/...`,
];

static flags = {
path: Flags.boolean({
description: 'Print the cache path instead of the contents.',
aliases: ['path'],
char: 'p',
default: false,
}),
};

static args = {
key: Args.string({ description: 'The key of a single cache entry to get.', required: false }),
};

async run(): Promise<void> {
const { args } = await this.parse(Get);
const { args, flags } = await this.parse(Get);

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

if (flags.path) {
this.log(ProjectCache.getCacheDir());
return;
}

const cache = ProjectCache.read();

let output = JSON.stringify(cache.raw(), mapReplacer);
Expand Down
1 change: 0 additions & 1 deletion src/commands/package/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
// SPDX-License-Identifier: Apache-2.0

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

Expand Down
10 changes: 10 additions & 0 deletions test/commands/cache/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// SPDX-License-Identifier: Apache-2.0

import { expect, test } from '@oclif/test';
import { getVelocitasRoot } from '../../../src/modules/package';
import { getCacheData } from '../../helpers/cache';
import { mockFolders } from '../../utils/mockfs';

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

test.do(() => {
mockFolders({ velocitasConfig: true });
})
.stdout()
.command(['cache get', '--path'])
.it('prints the cache path', (ctx) => {
expect(ctx.stdout.trim().startsWith(`${getVelocitasRoot()}/projects`)).to.be.true;
});

test.do(() => {
mockFolders({ velocitasConfig: true });
})
Expand Down

0 comments on commit 5f5506c

Please sign in to comment.