Skip to content

Commit bcb9876

Browse files
authored
chore: add flag to skip confirmation prompt on write actions (#635)
Signed-off-by: Tomás Migone <[email protected]>
1 parent 5575305 commit bcb9876

File tree

10 files changed

+34
-16
lines changed

10 files changed

+34
-16
lines changed

cli/cli.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ yargs
2727
.option('m', cliOpts.mnemonic)
2828
.option('p', cliOpts.providerUrl)
2929
.option('n', cliOpts.accountNumber)
30+
.option('s', cliOpts.skipConfirmation)
3031
.command(deployCommand)
3132
.command(migrateCommand)
3233
.command(proxyCommand)

cli/commands/airdrop.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ const createBatches = (
149149

150150
export const airdrop = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
151151
const graphToken = cli.contracts.GraphToken
152+
const skipConfirmation = cliArgs.skipConfirmation
152153

153154
// Load data
154155
const resumeList = loadResumeList(cliArgs.resumefile).map((r) => r.address)
@@ -179,7 +180,10 @@ export const airdrop = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<vo
179180
}
180181

181182
// Confirmation
182-
const sure = await confirm('Are you sure you want to proceed with the distribution?')
183+
const sure = await confirm(
184+
'Are you sure you want to proceed with the distribution?',
185+
skipConfirmation,
186+
)
183187
if (!sure) return
184188

185189
// Approve

cli/commands/deploy.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@ export const deploy = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<voi
1616
const initArgs = cliArgs.init
1717
const deployType = cliArgs.type
1818
const buildAcceptProxyTx = cliArgs.buildTx
19+
const skipConfirmation = cliArgs.skipConfirmation
1920

2021
// Ensure action
21-
const sure = await confirm(`Are you sure to deploy ${contractName}?`)
22+
const sure = await confirm(`Are you sure to deploy ${contractName}?`, skipConfirmation)
2223
if (!sure) return
2324

2425
// Deploy contract

cli/commands/migrate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,10 @@ export const migrate = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<vo
4040
const force = cliArgs.force
4141
const contractName = cliArgs.contract
4242
const chainId = cli.chainId
43+
const skipConfirmation = cliArgs.skipConfirmation
4344

4445
// Ensure action
45-
const sure = await confirm('Are you sure you want to migrate contracts?')
46+
const sure = await confirm('Are you sure you want to migrate contracts?', skipConfirmation)
4647
if (!sure) return
4748

4849
if (chainId == 1337) {

cli/commands/proxy/admin.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import { confirm } from '../../helpers'
88
export const setProxyAdmin = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promise<void> => {
99
const contractName = cliArgs.contract
1010
const adminAddress = cliArgs.admin
11+
const skipConfirmation = cliArgs.skipConfirmation
1112

1213
logger.info(`Set proxy admin for contract ${contractName} to ${adminAddress}`)
1314

1415
// Warn about changing ownership
15-
const sure = await confirm(`Are you sure to set the admin to ${adminAddress}?`)
16+
const sure = await confirm(`Are you sure to set the admin to ${adminAddress}?`, skipConfirmation)
1617
if (!sure) return
1718

1819
// Get address book info

cli/commands/proxy/upgrade.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,13 @@ export const upgradeProxy = async (cli: CLIEnvironment, cliArgs: CLIArgs): Promi
1010
const implAddress = cliArgs.impl
1111
const initArgs = cliArgs.init
1212
const buildAcceptProxyTx = cliArgs.buildTx
13+
const skipConfirmation = cliArgs.skipConfirmation
1314

1415
// Warn about upgrade
15-
const sure = await confirm(`Are you sure you want to upgrade ${contractName} to ${implAddress}?`)
16+
const sure = await confirm(
17+
`Are you sure you want to upgrade ${contractName} to ${implAddress}?`,
18+
skipConfirmation,
19+
)
1620
if (!sure) return
1721

1822
logger.info(`Upgrading contract ${contractName}...`)

cli/defaults.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,4 +56,10 @@ export const cliOpts = {
5656
type: 'boolean',
5757
default: false,
5858
},
59+
skipConfirmation: {
60+
alias: 'skip-confirmation',
61+
description: 'Skip confirmation prompt on write actions',
62+
type: 'boolean',
63+
default: false,
64+
},
5965
} as { [key: string]: Options }

cli/helpers.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@ export const pinMetadataToIPFS = async (
9191
return IPFS.ipfsHashToBytes32(metaHash)
9292
}
9393

94-
export const confirm = async (message: string): Promise<boolean> => {
94+
export const confirm = async (message: string, skip: boolean): Promise<boolean> => {
95+
if (skip) return true
9596
const res = await inquirer.prompt({
9697
name: 'confirm',
9798
type: 'confirm',

tasks/deployment/config.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import YAML from 'yaml'
77
import { Scalar, YAMLMap } from 'yaml/types'
88
import { HardhatRuntimeEnvironment } from 'hardhat/types'
99
import fs from 'fs'
10-
import inquirer from 'inquirer'
10+
import { confirm } from '../../cli/helpers'
1111

1212
interface Contract {
1313
name: string
@@ -93,10 +93,12 @@ const generalParams: GeneralParam[] = [
9393
task('update-config', 'Update graph config parameters with onchain data')
9494
.addParam('graphConfig', cliOpts.graphConfig.description, cliOpts.graphConfig.default)
9595
.addFlag('dryRun', "Only print the changes, don't write them to the config file")
96+
.addFlag('skipConfirmation', cliOpts.skipConfirmation.description)
9697
.setAction(async (taskArgs, hre) => {
9798
const networkName = hre.network.name
9899
const configFile = taskArgs.graphConfig
99100
const dryRun = taskArgs.dryRun
101+
const skipConfirmation = taskArgs.skipConfirmation
100102

101103
if (!fs.existsSync(configFile)) {
102104
throw new Error(`Could not find config file: ${configFile}`)
@@ -108,15 +110,11 @@ task('update-config', 'Update graph config parameters with onchain data')
108110

109111
// Prompt to avoid accidentally overwriting the config file with data from another network
110112
if (!configFile.includes(networkName)) {
111-
const res = await inquirer.prompt({
112-
name: 'confirm',
113-
type: 'confirm',
114-
default: false,
115-
message: `Config file ${configFile} doesn't match 'graph.<networkName>.yml'. Are you sure you want to continue?`,
116-
})
117-
if (!res.confirm) {
118-
return
119-
}
113+
const sure = await confirm(
114+
`Config file ${configFile} doesn't match 'graph.<networkName>.yml'. Are you sure you want to continue?`,
115+
skipConfirmation,
116+
)
117+
if (!sure) return
120118
}
121119

122120
const graphConfig = readConfig(configFile, true)

tasks/deployment/deploy.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import { migrate } from '../../cli/commands/migrate'
99
task('migrate', 'Migrate contracts')
1010
.addParam('addressBook', cliOpts.addressBook.description, cliOpts.addressBook.default)
1111
.addParam('graphConfig', cliOpts.graphConfig.description, cliOpts.graphConfig.default)
12+
.addFlag('skipConfirmation', cliOpts.skipConfirmation.description)
1213
.addFlag('force', cliOpts.force.description)
1314
.setAction(async (taskArgs, hre) => {
1415
const accounts = await hre.ethers.getSigners()

0 commit comments

Comments
 (0)