Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Adds "yes" option to setup-dev
Browse files Browse the repository at this point in the history
Summary:
Adds "yes" option to "setup-dev" command to accept all CLI questions with yes. This includes:

* Accept Android SDK licenses
* Accept Android platform, system, emulator licenses
* Accept to overwrite pytorch_live AVD

# Example

```
npx torchlive-cli setup-dev --yes
```

The short version is

```
npx torchlive-cli setup-dev -y
```

Note: the option will be used for the GitHub Action CI that tests the setup-dev command

## Test

Tested in forked repo: https://github.com/raedle/live/runs/4576829417

Reviewed By: liuyinglao

Differential Revision: D33229272

fbshipit-source-id: c8d288a19a865ae809f9e4ff524c66d481bee2e2
  • Loading branch information
raedle committed Dec 20, 2021
1 parent c1bfd39 commit 1f2e685
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 19 deletions.
9 changes: 7 additions & 2 deletions torchlive-cli/src/cli-commands/SetUpDev.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ import YarnInstaller from '../installers/YarnInstaller';
import {print as printHeader} from '../utils/header';
import {runTasks} from '../utils/TaskUtils';

const setUpDev = async (): Promise<void> => {
type SetupDevOptions = {
yes: boolean;
};

const setUpDev = async (options: SetupDevOptions): Promise<void> => {
printHeader();

const tasks: Array<IInstallerTask> = [
Expand All @@ -36,11 +40,12 @@ const setUpDev = async (): Promise<void> => {
new CocoaPodsInstaller(),
];

await runTasks(tasks);
await runTasks(tasks, options);
};

export function makeSetUpDevCommand() {
return new Command('setup-dev')
.description('set up development dependencies')
.option('-y, --yes', 'Accept all questions')
.action(setUpDev);
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,12 +135,16 @@ export default class AndroidEmulatorDeviceInstaller
}

async getUserConsentUpdate(context: TaskContext): Promise<boolean> {
const userConfirm = await context.task.prompt<boolean>({
type: 'confirm',
message: `The PyTorch Live Android emulator is either missing or out-of-date.
// Ask for user consent if accept all option is false or unset.
if (!context.ctx.yes) {
const userConfirm = await context.task.prompt<boolean>({
type: 'confirm',
message: `The PyTorch Live Android emulator is either missing or out-of-date.
Would you like to create or update the PyTorch Live Android emulator?`,
});
return userConfirm;
});
return userConfirm;
}
return true;
}
}
13 changes: 8 additions & 5 deletions torchlive-cli/src/installers/android/AndroidSDKInstaller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,14 @@ export default class AndroidSDKInstaller implements IInstallerTask {

const sdkRoot = getDefaultSDKPath();

await getUserConsentOnInstallerOrQuit(
this,
context,
'https://developer.android.com/studio/terms',
);
// Ask for user consent if accept all option is false or unset.
if (!context.ctx.yes) {
await getUserConsentOnInstallerOrQuit(
this,
context,
'https://developer.android.com/studio/terms',
);
}

const basicsCmd = `yes | ${sdkManager} --sdk_root=${sdkRoot} "tools"`;
await execCommand(context, basicsCmd);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ export default class AndroidSDKManagerInstaller
{encoding: 'utf-8'},
);

await getUserConsentOnInstallerOrQuit(
this,
context,
'https://developer.android.com/studio/terms.',
);
// Ask for user consent if accept all option is false or unset.
if (!context.ctx.yes) {
await getUserConsentOnInstallerOrQuit(
this,
context,
'https://developer.android.com/studio/terms.',
);
}

const licensesCmd = `yes | ${cltPath} --licenses`;
execCommand(context, licensesCmd);
Expand Down
7 changes: 5 additions & 2 deletions torchlive-cli/src/utils/TaskUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,10 @@ import {getEnv} from './SystemUtils';
const Logger = getLogger('TaskUtils');
const NOBREAKSPACE = '‎ ';

export async function runTasks(tasks: ITask[]): Promise<void> {
export async function runTasks(
tasks: ITask[],
taskContext: ListrContext = {},
): Promise<void> {
const validTasks = tasks.filter(task => task.isValid());

const taskList = new Listr(
Expand Down Expand Up @@ -92,7 +95,7 @@ export async function runTasks(tasks: ITask[]): Promise<void> {
);

try {
await taskList.run();
await taskList.run(taskContext);
} catch (error) {
const message = `
🚨 💥 🚨 💥 🚨
Expand Down

0 comments on commit 1f2e685

Please sign in to comment.