From 233416642308f65412b74ba18bca9b63073f3324 Mon Sep 17 00:00:00 2001 From: AnnaShaleva Date: Tue, 22 Mar 2022 14:56:50 +0300 Subject: [PATCH 1/2] cli: mark required flags of `generate-*` command --- cli/smartcontract/generate.go | 15 +++++++++------ cli/smartcontract/generate_test.go | 14 +++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/cli/smartcontract/generate.go b/cli/smartcontract/generate.go index 6965d527c..d95e90ca1 100644 --- a/cli/smartcontract/generate.go +++ b/cli/smartcontract/generate.go @@ -19,16 +19,19 @@ var generatorFlags = []cli.Flag{ Usage: "Configuration file to use", }, cli.StringFlag{ - Name: "manifest, m", - Usage: "Read contract manifest (*.manifest.json) file", + Name: "manifest, m", + Required: true, + Usage: "Read contract manifest (*.manifest.json) file", }, cli.StringFlag{ - Name: "out, o", - Usage: "Output of the compiled contract", + Name: "out, o", + Required: true, + Usage: "Output of the compiled contract", }, cli.StringFlag{ - Name: "hash", - Usage: "Smart-contract hash", + Name: "hash", + Required: true, + Usage: "Smart-contract hash", }, } diff --git a/cli/smartcontract/generate_test.go b/cli/smartcontract/generate_test.go index 47328dbcc..1b60f830e 100644 --- a/cli/smartcontract/generate_test.go +++ b/cli/smartcontract/generate_test.go @@ -415,18 +415,18 @@ func TestGenerate_Errors(t *testing.T) { require.True(t, strings.Contains(err.Error(), msg), "got: %v", err) } t.Run("invalid hash", func(t *testing.T) { - checkError(t, "invalid contract hash", "--hash", "xxx") + checkError(t, "invalid contract hash", "--hash", "xxx", "--manifest", "yyy", "--out", "zzz") }) t.Run("missing manifest argument", func(t *testing.T) { - checkError(t, errNoManifestFile.Error(), "--hash", util.Uint160{}.StringLE()) + checkError(t, "Required flag \"manifest\" not set", "--hash", util.Uint160{}.StringLE(), "--out", "zzz") }) t.Run("missing manifest file", func(t *testing.T) { - checkError(t, "can't read contract manifest", "--manifest", "notexists", "--hash", util.Uint160{}.StringLE()) + checkError(t, "can't read contract manifest", "--manifest", "notexists", "--hash", util.Uint160{}.StringLE(), "--out", "zzz") }) t.Run("empty manifest", func(t *testing.T) { manifestFile := filepath.Join(t.TempDir(), "invalid.json") require.NoError(t, os.WriteFile(manifestFile, []byte("[]"), os.ModePerm)) - checkError(t, "json: cannot unmarshal array into Go value of type manifest.Manifest", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE()) + checkError(t, "json: cannot unmarshal array into Go value of type manifest.Manifest", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(), "--out", "zzz") }) t.Run("invalid manifest", func(t *testing.T) { manifestFile := filepath.Join(t.TempDir(), "invalid.json") @@ -434,7 +434,7 @@ func TestGenerate_Errors(t *testing.T) { rawManifest, err := json.Marshal(m) require.NoError(t, err) require.NoError(t, os.WriteFile(manifestFile, rawManifest, os.ModePerm)) - checkError(t, "ABI: no methods", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE()) + checkError(t, "ABI: no methods", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(), "--out", "zzz") }) manifestFile := filepath.Join(t.TempDir(), "manifest.json") @@ -452,7 +452,7 @@ func TestGenerate_Errors(t *testing.T) { t.Run("missing config", func(t *testing.T) { checkError(t, "can't read config file", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(), - "--config", filepath.Join(t.TempDir(), "not.exists.yml")) + "--config", filepath.Join(t.TempDir(), "not.exists.yml"), "--out", "zzz") }) t.Run("invalid config", func(t *testing.T) { rawCfg := `package: wrapper @@ -464,6 +464,6 @@ callflags: checkError(t, "can't parse config file", "--manifest", manifestFile, "--hash", util.Uint160{}.StringLE(), - "--config", cfgPath) + "--config", cfgPath, "--out", "zzz") }) } From 7bab81f196f9e02bd6bad733d83a74d7c0191f81 Mon Sep 17 00:00:00 2001 From: Anna Shaleva Date: Wed, 28 Dec 2022 12:18:09 +0300 Subject: [PATCH 2/2] cli: adjust flags description for `smartcontract generate-*` --- cli/smartcontract/generate.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/smartcontract/generate.go b/cli/smartcontract/generate.go index d95e90ca1..47c662865 100644 --- a/cli/smartcontract/generate.go +++ b/cli/smartcontract/generate.go @@ -26,7 +26,7 @@ var generatorFlags = []cli.Flag{ cli.StringFlag{ Name: "out, o", Required: true, - Usage: "Output of the compiled contract", + Usage: "Output of the compiled wrapper", }, cli.StringFlag{ Name: "hash", @@ -38,7 +38,7 @@ var generatorFlags = []cli.Flag{ var generateWrapperCmd = cli.Command{ Name: "generate-wrapper", Usage: "generate wrapper to use in other contracts", - UsageText: "neo-go contract generate-wrapper --manifest --out --hash ", + UsageText: "neo-go contract generate-wrapper --manifest --out --hash [--config ]", Description: ``, Action: contractGenerateWrapper, Flags: generatorFlags, @@ -47,7 +47,7 @@ var generateWrapperCmd = cli.Command{ var generateRPCWrapperCmd = cli.Command{ Name: "generate-rpcwrapper", Usage: "generate RPC wrapper to use for data reads", - UsageText: "neo-go contract generate-rpcwrapper --manifest --out --hash ", + UsageText: "neo-go contract generate-rpcwrapper --manifest --out --hash [--config ]", Action: contractGenerateRPCWrapper, Flags: generatorFlags, }