Skip to content

Commit

Permalink
feat: update to oclif/core v2 (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdonnalley authored Jan 30, 2023
1 parent 65c6f40 commit d92b44a
Show file tree
Hide file tree
Showing 5 changed files with 250 additions and 108 deletions.
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2022, Salesforce.com, Inc.
Copyright (c) 2023, Salesforce.com, Inc.
All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Expand Down
10 changes: 5 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
"author": "Salesforce",
"bugs": "https://github.com/forcedotcom/cli/issues",
"dependencies": {
"@oclif/core": "^1.8.0",
"@oclif/core": "^2.0.7",
"@salesforce/core": "^3.32.2",
"@salesforce/telemetry": "^3.2.5",
"debug": "^4.3.4",
"tslib": "^2"
},
"devDependencies": {
"@oclif/plugin-command-snapshot": "^3.2.11",
"@oclif/plugin-help": "^3.0.1",
"@oclif/plugin-command-snapshot": "^3.3.2",
"@oclif/plugin-help": "^5.2.2",
"@salesforce/cli-plugins-testkit": "^3.2.18",
"@salesforce/dev-config": "^3.0.1",
"@salesforce/dev-scripts": "^3.1.0",
Expand All @@ -36,7 +36,7 @@
"husky": "^7.0.4",
"mocha": "^9.1.3",
"nyc": "^15.1.0",
"oclif": "^3.2.28",
"oclif": "^3.6.1",
"prettier": "^2.7.1",
"pretty-quick": "^3.1.0",
"shx": "0.3.4",
Expand Down Expand Up @@ -99,4 +99,4 @@
"publishConfig": {
"access": "public"
}
}
}
15 changes: 8 additions & 7 deletions src/commandExecution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,16 @@

import { join } from 'path';
import * as fs from 'fs';
import { Config, Interfaces, Parser } from '@oclif/core';
import { Config, Command, Parser } from '@oclif/core';
import { FlagInput } from '@oclif/core/lib/interfaces/parser';
import { SfProject } from '@salesforce/core';
import { AsyncCreatable } from '@salesforce/kit';
import { isNumber, JsonMap, Optional } from '@salesforce/ts-types';
import { debug } from './debuger';
import { InitData } from './hooks/telemetryInit';

export type CommandExecutionOptions = {
command: Partial<Interfaces.Command.Class>;
command: Partial<Command.Class>;
argv: string[];
config: Partial<Config>;
};
Expand All @@ -31,7 +32,7 @@ export class CommandExecution extends AsyncCreatable {
private upTimeAtCmdStart: number;
private specifiedFlags: string[] = [];
private specifiedFlagFullNames: string[] = [];
private command: Partial<Interfaces.Command.Class>;
private command: Partial<Command.Class>;
private argv: string[];
private config: Partial<Config>;
private vcs?: string;
Expand Down Expand Up @@ -146,23 +147,23 @@ export class CommandExecution extends AsyncCreatable {
const commandDef = { flags: flagDefinitions, args: this.command.args, strict: !anyCmd.varargs };

// eslint-disable-next-line @typescript-eslint/no-explicit-any
let flags: Interfaces.Input<any> = {};
let flags: FlagInput = {};
try {
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
flags = (await Parser.parse(argv, commandDef)).flags;
} catch (error) {
debug('Error parsing flags');
}
this.orgUsername = flags['targetusername'] as string;
this.devHubOrgUsername = flags['targetdevhubusername'] as string;
this.orgUsername = flags['targetusername'] as unknown as string;
this.devHubOrgUsername = flags['targetdevhubusername'] as unknown as string;

this.determineSpecifiedFlags(argv, flags, flagDefinitions);

this.vcs = await CommandExecution.resolveVCSInfo();
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
private determineSpecifiedFlags(argv: string[], flags: any, flagDefinitions: Interfaces.Input<any>): void {
private determineSpecifiedFlags(argv: string[], flags: any, flagDefinitions: FlagInput): void {
// Help won't be in the parsed flags
const shortHelp = argv.find((arg) => /^-h$/.test(arg));
const fullHelp = argv.find((arg) => /^--help$/.test(arg));
Expand Down
18 changes: 4 additions & 14 deletions test/helpers/myCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
* For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/

import { Flags, Config } from '@oclif/core';
import { Flags, Command } from '@oclif/core';

export class MyCommand {
export class MyCommand extends Command {
public static id = 'test';
public static hidden = false;
public static aliases = [];
Expand All @@ -17,20 +17,10 @@ export class MyCommand {
targetusername: Flags.string(),
targetdevhubusername: Flags.string(),
};
public static args = [];

public static _base = '';

// eslint-disable-next-line @typescript-eslint/no-unused-vars
public constructor(argv: string[], config: Config) {}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
public static run(): PromiseLike<any> {
return Promise.resolve();
}
public static args = {};

// eslint-disable-next-line class-methods-use-this
public _run(): Promise<void> {
public async run(): Promise<void> {
return Promise.resolve();
}
}
Loading

0 comments on commit d92b44a

Please sign in to comment.