diff --git a/README.md b/README.md index fdc7940..f0a185e 100644 --- a/README.md +++ b/README.md @@ -19,34 +19,34 @@ go install ./... ## Usage ``` -Usage: ccmetadata -cert= -key= -mspid= -connection= -channel= [-aslocalhost] [-verbose] +Usage: ccmetadata --cert= --key= --mspid= --connection= --channel= [--aslocalhost] [--verbose] 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/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem \ --key=organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/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/User1@org1.example.com/msp/signcerts/User1@org1.example.com-cert.pem \ +--key=organizations/peerOrganizations/org1.example.com/users/User1@org1.example.com/msp/keystore/priv_sk \ +--mspid=Org1MSP \ +--connection=organizations/peerOrganizations/org1.example.com/connection-org1.yaml \ +--channel=mychannel \ +--aslocalhost \ basic ``` diff --git a/cmd/ccmetadata/main.go b/cmd/ccmetadata/main.go index f0f2ee8..531454e 100644 --- a/cmd/ccmetadata/main.go +++ b/cmd/ccmetadata/main.go @@ -14,20 +14,44 @@ import ( ) func usage() { - fmt.Fprintf(os.Stderr, "Usage: ccmetadata -cert= -key= -mspid= -connection= -channel= [-aslocalhost] [-verbose] \n\nGet metadata for the specified chaincode name\n\n") - flag.PrintDefaults() + fmt.Fprintf(os.Stderr, "Usage: ccmetadata --cert= --key= --mspid= --connection= --channel= [--aslocalhost] [--verbose] \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() @@ -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), @@ -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) }