add version option
This commit is contained in:
parent
35359585cb
commit
b2df2f59c4
3 changed files with 45 additions and 6 deletions
|
@ -2,9 +2,9 @@
|
|||
"name": "@immich/cli",
|
||||
"version": "2.0.4",
|
||||
"description": "Command Line Interface (CLI) for Immich",
|
||||
"main": "dist/index.js",
|
||||
"main": "dist/src/index.js",
|
||||
"bin": {
|
||||
"immich": "./dist/index.js"
|
||||
"immich": "./dist/src/index.js"
|
||||
},
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
|
37
cli/src/constants.ts
Normal file
37
cli/src/constants.ts
Normal file
|
@ -0,0 +1,37 @@
|
|||
import pkg from '../package.json';
|
||||
|
||||
export interface ICLIVersion {
|
||||
major: number;
|
||||
minor: number;
|
||||
patch: number;
|
||||
}
|
||||
|
||||
export class CLIVersion implements ICLIVersion {
|
||||
constructor(
|
||||
public readonly major: number,
|
||||
public readonly minor: number,
|
||||
public readonly patch: number,
|
||||
) {}
|
||||
|
||||
toString() {
|
||||
return `${this.major}.${this.minor}.${this.patch}`;
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
const { major, minor, patch } = this;
|
||||
return { major, minor, patch };
|
||||
}
|
||||
|
||||
static fromString(version: string): CLIVersion {
|
||||
const regex = /(?:v)?(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)/i;
|
||||
const matchResult = version.match(regex);
|
||||
if (matchResult) {
|
||||
const [, major, minor, patch] = matchResult.map(Number);
|
||||
return new CLIVersion(major, minor, patch);
|
||||
} else {
|
||||
throw new Error(`Invalid version format: ${version}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export const cliVersion = CLIVersion.fromString(pkg.version);
|
|
@ -7,14 +7,16 @@ import LoginKey from './commands/login/key';
|
|||
import Logout from './commands/logout';
|
||||
import path from 'node:path';
|
||||
import os from 'os';
|
||||
import { cliVersion } from './constants';
|
||||
|
||||
const userHomeDir = os.homedir();
|
||||
const configDir = path.join(userHomeDir, '.config/immich/');
|
||||
|
||||
const program = new Command();
|
||||
program.name('immich');
|
||||
program.description('Immich command line interface');
|
||||
program.addOption(new Option('-d, --config', 'Configuration directory').env('IMMICH_CONFIG_DIR').default(configDir));
|
||||
const program = new Command()
|
||||
.name('immich')
|
||||
.version(cliVersion.toString())
|
||||
.description('Immich command line interface')
|
||||
.addOption(new Option('-d, --config', 'Configuration directory').env('IMMICH_CONFIG_DIR').default(configDir));
|
||||
|
||||
program
|
||||
.command('upload')
|
||||
|
|
Loading…
Reference in a new issue