Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi committed Nov 1, 2023
1 parent ed84523 commit e1af770
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 51 deletions.
36 changes: 18 additions & 18 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 16 additions & 18 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ export class CLI {
applyCommandConfig(this, cmdName, cmd, conf);

if (conf.platforms) {
this.debugLogger.trace(`Detected conf.platforms applying config for "${cmd.name()}", overriding createHelp()`);
this.command.createHelp = () => {
return Object.assign(new TiHelp(this, conf.platforms), this.command.configureHelp());
};
Expand Down Expand Up @@ -548,6 +549,10 @@ export class CLI {
await program.parseAsync();
this.debugLogger.trace('Finished parsing arguments first pass');

if (this.command === program && program.args.length) {
throw new TiError(`Unknown command "${program.args[0]}"`, { showHelp: true });
}

// reset hooks
const resetHooksAndOptionHandlers = ctx => {
ctx._lifeCycleHooks = {};
Expand Down Expand Up @@ -612,6 +617,8 @@ export class CLI {
const platformConf = this.command.conf.platforms[this.argv.platform];

this.argv.$platform = this.argv.platform;

// set platform context
this.command.platform = {
conf: platformConf
};
Expand Down Expand Up @@ -688,23 +695,6 @@ export class CLI {

// TODO: Prompt for missing required options

// // any keys in the conf object that aren't explicitly 'flags',
// // 'options', 'args', or 'subcommands' is probably a option branch
// // that changes the available flags/options
// const skipRegExp = /^(flags|options|args|subcommands)$/;
// const optionBranches = Object.keys(conf)
// .filter(name => conf.options && conf.options[name] && !skipRegExp.test(name))
// .sort((a, b) => {
// // if we have multiple option groups, then try to process them in order
// if (!conf.options[a] || !conf.options[a].order) {
// return 1;
// }
// if (!conf.options[b] || !conf.options[b].order) {
// return -1;
// }
// return conf.options[b].order - conf.options[a].order;
// });

// for (const name of optionBranches) {
// const option = conf.options[name];
// const optionBranch = conf[name];
Expand Down Expand Up @@ -785,7 +775,7 @@ export class CLI {
cmdName,
config: this.config,
cwd,
logger: this.debugLogger,
logger: this.logger,
promptingEnabled: this.promptingEnabled,
selectedSdk: this.argv.sdk
});
Expand Down Expand Up @@ -878,6 +868,13 @@ export class CLI {
this.debugLogger.trace(`Importing: ${commandFile}`);
cmd.module = (await import(commandFile)) || {};

// check if this command is compatible with this version of the CLI
if (cmd.module.cliVersion && !version.satisfies(this.version, cmd.module.cliVersion)) {
throw new TiError(`Command "${cmdName}" incompatible with this version of the CLI`, {
after: `Requires version ${cmd.module.cliVersion}, currently ${this.version}`
});
}

if (typeof cmd.module.extendedDesc === 'string') {
desc = cmd.module.extendedDesc;
} else if (desc) {
Expand All @@ -900,6 +897,7 @@ export class CLI {
}

if (conf.platforms) {
this.debugLogger.trace(`Detected conf.platforms loading "${cmdName}", overriding createHelp()`);
this.command.createHelp = () => {
return Object.assign(new TiHelp(this, conf.platforms), this.command.configureHelp());
};
Expand Down
2 changes: 1 addition & 1 deletion src/commands/info.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ export async function run(logger, config, cli) {
({
data,
platformInfo
} = await detect(logger, config, cli, types));
} = await detect(cli.debugLogger, config, cli, types));
} finally {
busy?.stop();
}
Expand Down
8 changes: 6 additions & 2 deletions src/commands/module.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ export function config(logger, config, cli) {
* @param {Function} finished - Callback when the command finishes
*/
export async function run(logger, config, cli) {
const action = cli.command.name();
let action = cli.command.name();
if (action === 'list' && cli.command.args.length) {
action = cli.command.args[0];
cli.command = cli.command.parent;
}
for (const [name, subcommand] of Object.entries(ModuleSubcommands)) {
if (action === name || action === subcommand.alias) {
await ModuleSubcommands[name].fn(logger, config, cli);
Expand Down Expand Up @@ -145,7 +149,7 @@ ModuleSubcommands.list = {
}
}

const results = await detect(searchPaths, config, logger);
const results = await detect(searchPaths, config, cli.debugLogger);

if (isJson) {
logger.log(JSON.stringify(results, null, '\t'));
Expand Down
6 changes: 5 additions & 1 deletion src/commands/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ export function config(logger, config, cli) {
* @param {CLI} cli - The CLI instance
*/
export async function run(logger, config, cli) {
const action = cli.command.name();
let action = cli.command.name();
if (action === 'list' && cli.command.args.length) {
action = cli.command.args[0];
cli.command = cli.command.parent;
}
for (const [name, subcommand] of Object.entries(SdkSubcommands)) {
if (action === name || action === subcommand.alias) {
await SdkSubcommands[name].fn(logger, config, cli);
Expand Down
5 changes: 5 additions & 0 deletions src/util/prompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
export async function prompt(opts) {
const { default: prompts } = await import('prompts');
const { prompt } = prompts;

if (Array.isArray(opts)) {
return await prompt(opts);
}

const { value } = await prompt({
...opts,
name: 'value'
Expand Down
15 changes: 7 additions & 8 deletions src/util/setup-screens.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,9 @@ export class SetupScreens {
} Exit`
);

const { value } = await prompt({
const value = await prompt({
type: 'text',
message: 'Where do you want to go?',
name: 'value'
message: 'Where do you want to go?'
});

const next = lookup[value];
Expand All @@ -124,7 +123,7 @@ export class SetupScreens {
busy.start();

try {
({ data } = await detect(this.logger, this.config, this.cli, { all: true }));
({ data } = await detect(this.cli.debugLogger, this.config, this.cli, { all: true }));
} finally {
busy.stop();
}
Expand Down Expand Up @@ -209,7 +208,7 @@ export class SetupScreens {
}

try {
({ data } = await detect(this.logger, this.config, this.cli, { all: true }));
({ data } = await detect(this.cli.debugLogger, this.config, this.cli, { all: true }));

data.titaniumCLI.latest = await request('https://registry.npmjs.org/-/package/titanium/dist-tags')
.then(res => res.body.json())
Expand Down Expand Up @@ -287,7 +286,7 @@ export class SetupScreens {
busy.start();

try {
({ data } = await detect(this.logger, this.config, this.cli, { all: true }));
({ data } = await detect(this.cli.debugLogger, this.config, this.cli, { all: true }));
} finally {
busy.stop();
}
Expand Down Expand Up @@ -714,7 +713,7 @@ export class SetupScreens {
busy.start();

try {
({ data } = await detect(this.logger, this.config, this.cli, { all: true }));
({ data } = await detect(this.cli.debugLogger, this.config, this.cli, { all: true }));
} finally {
busy.stop();
}
Expand Down Expand Up @@ -797,7 +796,7 @@ export class SetupScreens {
busy.start();

try {
({ data } = await detect(this.logger, this.config, this.cli, { all: true }));
({ data } = await detect(this.cli.debugLogger, this.config, this.cli, { all: true }));
} finally {
busy.stop();
}
Expand Down
5 changes: 2 additions & 3 deletions src/util/tisdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,13 +193,12 @@ export async function initSDK({ cmdName, config, cwd, logger, promptingEnabled,
}
}

({ sdkVersion } = await prompt({
sdkVersion = await prompt({
type: 'select',
message: 'Which Titanium SDK would you like to use?',
name: 'sdkVersion',
initial: sdk ? choices.find(s => s.name === sdk.name)?.name : undefined,
choices
}));
});

if (sdkVersion === undefined) {
// sigint
Expand Down

0 comments on commit e1af770

Please sign in to comment.