Skip to content

Commit

Permalink
Fixed branch option double prompting, cleaned up sdk select text
Browse files Browse the repository at this point in the history
  • Loading branch information
cb1kenobi committed Jan 10, 2024
1 parent 4da671b commit 1679630
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 53 deletions.
94 changes: 48 additions & 46 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,7 +632,7 @@ export class CLI {
if (conf.options) {
for (const name of Object.keys(conf.options)) {
if (!Object.hasOwn(this.argv, name) && conf.options[name].default !== undefined) {
this.argv[name] = conf.options[name].default;
cmd.setOptionValue(name, this.argv[name] = conf.options[name].default);
}
}
}
Expand Down Expand Up @@ -1012,9 +1012,11 @@ export class CLI {
* @access private
*/
async prompt(opt) {
let value;
this.debugLogger.trace(`Prompting for --${opt.name}`);

if (typeof opt.prompt === 'function') {
// option has it's own prompt handler which probably uses `fields`
const field = await new Promise(resolve => opt.prompt(resolve));
if (!field) {
return;
Expand All @@ -1024,7 +1026,7 @@ export class CLI {
field.autoSelectOne = false;
}

const value = await new Promise(resolve => {
value = await new Promise(resolve => {
field.prompt((err, value) => {
if (err) {
process.exit(1);
Expand All @@ -1033,60 +1035,60 @@ export class CLI {
resolve(value);
});
});
return this.argv[opt.name] = value;
}

const pr = opt.prompt || {};
const p = (pr.label || capitalize(opt.desc || '')).trim().replace(/:$/, '');
let def = pr.default || opt.default || '';
if (typeof def === 'function') {
def = def();
} else if (Array.isArray(def)) {
def = def.join(',');
}

const validate = pr.validate || (value => {
if (pr.validator) {
try {
pr.validator(value);
} catch (ex) {
return ex.toString();
}
} else if (!value.length || (pr.pattern && !pr.pattern.test(value))) {
return pr.error;
} else {
// use the generic prompt
const pr = opt.prompt || {};
const p = (pr.label || capitalize(opt.desc || '')).trim().replace(/:$/, '');
let def = pr.default || opt.default || '';
if (typeof def === 'function') {
def = def();
} else if (Array.isArray(def)) {
def = def.join(',');
}
return true;
});

let value;
const validate = pr.validate || (value => {
if (pr.validator) {
try {
pr.validator(value);
} catch (ex) {
return ex.toString();
}
} else if (!value.length || (pr.pattern && !pr.pattern.test(value))) {
return pr.error;
}
return true;
});

if (Array.isArray(opt.values)) {
if (opt.values.length > 1) {
const choices = opt.values.map(v => ({ label: v, value: v }));
if (Array.isArray(opt.values)) {
if (opt.values.length > 1) {
const choices = opt.values.map(v => ({ label: v, value: v }));
value = await prompt({
type: 'select',
message: p,
initial: def && choices.find(c => c.value === def) || undefined,
validate,
choices
});
} else {
value = opt.values[0];
}
} else {
value = await prompt({
type: 'select',
type: opt.password ? 'password' : 'text',
message: p,
initial: def && choices.find(c => c.value === def) || undefined,
validate,
choices
initial: def || undefined,
validate
});
} else {
value = opt.values[0];
}
} else {
value = await prompt({
type: opt.password ? 'password' : 'text',
message: p,
initial: def || undefined,
validate
});
}

if (value === undefined) {
// sigint
process.exit(0);
if (value === undefined) {
// sigint
process.exit(0);
}
}

this.debugLogger.trace(`Selected value = ${value}`);
this.command.setOptionValue(opt.name, value);
return this.argv[opt.name] = value;
}

Expand Down
8 changes: 4 additions & 4 deletions src/commands/sdk.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ SdkSubcommands.select = {
logger.log(
yellow(
wrapAnsi(
`The "select" subcommand is no longer used.
`Good news! The "select" subcommand is no longer required.
The Titanium CLI will automatically use the latest stable SDK release, if installed.
If the current working directory is a Titanium app, the Titanium CLI will automatically use the <sdk-version> from the "tiapp.xml".`,
If the current working directory is a Titanium app, the Titanium CLI will
automatically use the <sdk-version> from the "tiapp.xml", otherwise use the
default to the latest installed SDK.`,
config.get('cli.width', 80),
{ hard: true, trim: false }
)
Expand Down
3 changes: 0 additions & 3 deletions src/util/apply-command-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ export function applyCommandConfig(cli, cmdName, cmd, conf) {
}

conf.options[name] = new Proxy(meta, {
get(obj, prop) {
return obj[prop];
},
set(obj, prop, value) {
const orig = obj[prop];
obj[prop] = value;
Expand Down

0 comments on commit 1679630

Please sign in to comment.