Skip to content

Commit 0db8961

Browse files
authored
fix(cli): fix bug on interact package ref cli input validation (usecannon#488)
1 parent 26b0c13 commit 0db8961

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

packages/cli/src/index.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,9 @@ program
645645
const outputs = await getOutputs(runtime, new ChainDefinition(deployData.def), deployData.state);
646646

647647
if (!outputs) {
648-
throw new Error(`no cannon build found for chain ${networkInfo.chainId}/${opts.preset}. Did you mean to run instead?`);
648+
throw new Error(
649+
`no cannon build found for chain ${networkInfo.chainId}/${selectedPreset}. Did you mean to run instead?`
650+
);
649651
}
650652

651653
const contracts = [getContractsRecursive(outputs, p.provider)];

packages/cli/src/util/params.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,19 @@ export function parseSettings(values: string[] = []) {
3333
}
3434

3535
export function parsePackageArguments(val: string, result?: PackageSpecification): PackageSpecification {
36-
if (!result) {
36+
const packageMatch = PackageReference.isValid(val);
37+
38+
if (!result && !packageMatch) {
3739
throw new InvalidArgumentError(
3840
'First argument should be a cannon package name, e.g.: greeter:1.0.0 or greeter:latest@main'
3941
);
4042
}
4143

42-
if (PackageReference.isValid(val)) {
44+
if (result && !_.isEmpty(result) && packageMatch) {
45+
throw new InvalidArgumentError('You can only specify a single cannon package');
46+
}
47+
48+
if (packageMatch) {
4349
const pkg = new PackageReference(val);
4450

4551
if (!_.isEmpty(result)) {
@@ -69,7 +75,9 @@ export function parsePackageArguments(val: string, result?: PackageSpecification
6975
}
7076

7177
export function parsePackagesArguments(val: string, result: PackageSpecification[] = []) {
72-
if (PackageReference.isValid(val)) {
78+
const packageMatch = PackageReference.isValid(val);
79+
80+
if (packageMatch) {
7381
const pkg = new PackageReference(val);
7482
const { name, version, preset } = pkg;
7583

packages/cli/src/util/provider.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@ const debug = Debug('cannon:cli:provider');
1414
export async function resolveWriteProvider(settings: CliSettings, chainId: number | string) {
1515
if (settings.providerUrl.split(',')[0] == 'frame' && !settings.quiet) {
1616
console.warn(
17-
`\nUsing Frame as the default provider. If you don't have Frame installed, Cannon defaults to http://localhost:8545. \n
18-
\n`
17+
"\nUsing Frame as the default provider. If you don't have Frame installed, Cannon defaults to http://localhost:8545."
1918
);
2019
console.warn(
2120
`Set a custom provider url in your settings (run ${bold('cannon setup')}) or pass it as an env variable (${bold(

0 commit comments

Comments
 (0)