Skip to content

Commit

Permalink
Add short options
Browse files Browse the repository at this point in the history
Signed-off-by: James Taylor <[email protected]>
  • Loading branch information
jt-nti committed Feb 10, 2022
1 parent 904d757 commit 38c7955
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 36 deletions.
34 changes: 17 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,34 +19,34 @@ go install ./...
## Usage

```
Usage: ccmetadata -cert=<path> -key=<path> -mspid=<name> -connection=<path> -channel=<name> [-aslocalhost] [-verbose] <chaincode>
Usage: ccmetadata --cert=<path> --key=<path> --mspid=<name> --connection=<path> --channel=<name> [--aslocalhost] [--verbose] <chaincode>
Get metadata for the specified chaincode name
-aslocalhost
use discovery service as localhost
-cert string
-c, --cert string
certificate file
-channel string
channel name, e.g. mychannel
-connection string
connection profile file
-key string
-k, --key string
private key file
-mspid string
-m, --mspid string
private key file, e.g. Org1MSP
-verbose
-p, --connection string
connection profile file
-n, --channel string
channel name, e.g. mychannel
-l, --aslocalhost
use discovery service as localhost
-v, --verbose
enable verbose logging
```

For example, in the _fabric-samples/test-network_ directory:

```
ccmetadata -cert=organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected] \
-key=organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk \
-mspid=Org1MSP \
-connection=organizations/peerOrganizations/org1.example.com/connection-org1.yaml \
-channel=mychannel \
-aslocalhost \
ccmetadata --cert=organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected] \
--key=organizations/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/priv_sk \
--mspid=Org1MSP \
--connection=organizations/peerOrganizations/org1.example.com/connection-org1.yaml \
--channel=mychannel \
--aslocalhost \
basic
```
62 changes: 43 additions & 19 deletions cmd/ccmetadata/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,44 @@ import (
)

func usage() {
fmt.Fprintf(os.Stderr, "Usage: ccmetadata -cert=<path> -key=<path> -mspid=<name> -connection=<path> -channel=<name> [-aslocalhost] [-verbose] <chaincode>\n\nGet metadata for the specified chaincode name\n\n")
flag.PrintDefaults()
fmt.Fprintf(os.Stderr, "Usage: ccmetadata --cert=<path> --key=<path> --mspid=<name> --connection=<path> --channel=<name> [--aslocalhost] [--verbose] <chaincode>\n\n")

fmt.Fprintf(os.Stderr, "Get metadata for the specified chaincode name\n\n")

fmt.Fprintf(os.Stderr, " -c, --cert string\n certificate file\n")
fmt.Fprintf(os.Stderr, " -k, --key string\n private key file\n")
fmt.Fprintf(os.Stderr, " -m, --mspid string\n private key file, e.g. Org1MSP\n")
fmt.Fprintf(os.Stderr, " -p, --connection string\n connection profile file\n")
fmt.Fprintf(os.Stderr, " -n, --channel string\n channel name, e.g. mychannel\n")
fmt.Fprintf(os.Stderr, " -l, --aslocalhost\n use discovery service as localhost\n")
fmt.Fprintf(os.Stderr, " -v, --verbose\n enable verbose logging\n")
}

func main() {
var certPath string
var keyPath string
var mspid string
var ccpPath string
var channelName string
var aslocalhost bool
var verbose bool

flag.Usage = usage

certPath := flag.String("cert", "", "certificate file")
keyPath := flag.String("key", "", "private key file")
mspid := flag.String("mspid", "", "private key file, e.g. Org1MSP")
ccpPath := flag.String("connection", "", "connection profile file")
channelName := flag.String("channel", "", "channel name, e.g. mychannel")
aslocalhost := flag.Bool("aslocalhost", false, "use discovery service as localhost")
verbose := flag.Bool("verbose", false, "enable verbose logging")
flag.StringVar(&certPath, "cert", "", "certificate file")
flag.StringVar(&certPath, "c", "", "certificate file")
flag.StringVar(&keyPath, "key", "", "private key file")
flag.StringVar(&keyPath, "k", "", "private key file")
flag.StringVar(&mspid, "mspid", "", "private key file, e.g. Org1MSP")
flag.StringVar(&mspid, "m", "", "private key file, e.g. Org1MSP")
flag.StringVar(&ccpPath, "connection", "", "connection profile file")
flag.StringVar(&ccpPath, "p", "", "connection profile file")
flag.StringVar(&channelName, "channel", "", "channel name, e.g. mychannel")
flag.StringVar(&channelName, "n", "", "channel name, e.g. mychannel")
flag.BoolVar(&aslocalhost, "aslocalhost", false, "use discovery service as localhost")
flag.BoolVar(&aslocalhost, "l", false, "use discovery service as localhost")
flag.BoolVar(&verbose, "verbose", false, "enable verbose logging")
flag.BoolVar(&verbose, "v", false, "enable verbose logging")

flag.Parse()

Expand All @@ -49,30 +73,30 @@ func main() {
}
chaincodeName := flag.Arg(0)

if *verbose {
fmt.Printf("Certificate file: %s\n", *certPath)
fmt.Printf("Private key file: %s\n", *keyPath)
fmt.Printf("MSP ID: %s\n", *mspid)
fmt.Printf("Channel name: %s\n", *channelName)
fmt.Printf("As localhost option: %t\n", *aslocalhost)
if verbose {
fmt.Printf("Certificate file: %s\n", certPath)
fmt.Printf("Private key file: %s\n", keyPath)
fmt.Printf("MSP ID: %s\n", mspid)
fmt.Printf("Channel name: %s\n", channelName)
fmt.Printf("As localhost option: %t\n", aslocalhost)
fmt.Printf("Chaincode name: %s\n", chaincodeName)
} else {
logging.SetLevel("", logging.ERROR)
}

if *aslocalhost {
if aslocalhost {
err := os.Setenv("DISCOVERY_AS_LOCALHOST", "true")
if err != nil {
log.Fatalf("Failed to set DISCOVERY_AS_LOCALHOST environment variable: %v", err)
}
}

wallet, err := createWallet(*certPath, *keyPath, *mspid)
wallet, err := createWallet(certPath, keyPath, mspid)
if err != nil {
log.Fatalf("Failed to get credentials: %v", err)
}

connectionConfig := config.FromFile(filepath.Clean(*ccpPath))
connectionConfig := config.FromFile(filepath.Clean(ccpPath))

gateway, err := gateway.Connect(
gateway.WithConfig(connectionConfig),
Expand All @@ -83,7 +107,7 @@ func main() {
}
defer gateway.Close()

network, err := gateway.GetNetwork(*channelName)
network, err := gateway.GetNetwork(channelName)
if err != nil {
log.Fatalf("Failed to get network: %v", err)
}
Expand Down

0 comments on commit 38c7955

Please sign in to comment.