Skip to content

Commit e27dc9e

Browse files
authored
Merge pull request #60 from Azure/dev
Improved help output for options.
2 parents bd9fc0c + 3cd9a5d commit e27dc9e

File tree

2 files changed

+62
-16
lines changed

2 files changed

+62
-16
lines changed

blobporter.go

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"net/url"
1010
"os"
1111
"runtime"
12+
"strconv"
1213
"strings"
1314
"sync/atomic"
1415
"time"
@@ -45,7 +46,7 @@ const (
4546
// User can use environment variables to specify storage account information
4647
storageAccountNameEnvVar = "ACCOUNT_NAME"
4748
storageAccountKeyEnvVar = "ACCOUNT_KEY"
48-
programVersion = "0.5.02" // version number to show in help
49+
programVersion = "0.5.03" // version number to show in help
4950
)
5051

5152
const numOfWorkersFactor = 9
@@ -66,20 +67,55 @@ func init() {
6667
extraWorkerBufferSlots = 5
6768
)
6869

69-
util.StringListVarAlias(&sourceURIs, "f", "file", "", "URL, file or files (e.g. /data/*.gz) to upload. Destination file for download.")
70-
util.StringListVarAlias(&blobNames, "n", "name", "", "Blob name to upload or download from Azure Blob Storage. Destination file for download from URL")
71-
util.StringVarAlias(&containerName, "c", "container_name", "", "container name (e.g. mycontainer)")
72-
util.IntVarAlias(&numberOfWorkers, "g", "concurrent_workers", defaultNumberOfWorkers, " Number of routines for parallel upload")
73-
util.IntVarAlias(&numberOfReaders, "r", "concurrent_readers", defaultNumberOfReaders, " Number of threads for parallel reading of the input file")
74-
util.StringVarAlias(&blockSizeStr, "b", "block_size", blockSizeStr, " Desired size of each blob block. Can be specified an integer byte count or integer suffixed with B, KB, MB, or GB. ")
75-
util.BoolVarAlias(&util.Verbose, "v", "verbose", false, " Display verbose output")
76-
util.BoolVarAlias(&quietMode, "q", "quiet_mode", false, " Quiet mode, no progress information is written to the stdout. Errors, warnings and final summary still are written")
77-
util.BoolVarAlias(&calculateMD5, "m", "compute_blockmd5", false, " Computes the MD5 for the block and includes the value in the block request")
78-
util.IntVarAlias(&util.HTTPClientTimeout, "s", "http_timeout", util.HTTPClientTimeout, "HTTP client timeout in seconds. Default value is 600s.")
79-
util.StringVarAlias(&storageAccountName, "a", "account_name", "", " Storage account name (e.g. mystorage). Can also be specified via the "+storageAccountNameEnvVar+" environment variable.")
80-
util.StringVarAlias(&storageAccountKey, "k", "account_key", "", " Storage account key string. Can also be specified via the "+storageAccountKeyEnvVar+" environment variable.")
81-
util.StringVarAlias(&dedupeLevelOptStr, "d", "dup_check_level", dedupeLevelOptStr, " Desired level of effort to detect duplicate data blocks to minimize upload size. Must be one of "+transfer.DupeCheckLevelStr)
82-
util.StringVarAlias(&transferDefStr, "t", "transfer_definition", string(defaultTransferDef), "Defines the type of source and target in the transfer. Must be one of file-blockblob, file-pageblob, http-blockblob, http-pageblob, blob-file, pageblock-file (alias of blob-file), blockblob-file (alias of blob-file) or http-file")
70+
const (
71+
fileMsg = "URL, file or files (e.g. /data/*.gz) to upload.\n\tDestination file for download."
72+
nameMsg = "Blob name for upload or download scenarios from Azure Blob Storage.\n\tDestination file name for downloads from a URL."
73+
containerNameMsg = "Container name (e.g. mycontainer).\n\tIf the container does not exist, it will be created."
74+
concurrentWorkersMsg = "Number of workers for parallel upload."
75+
concurrentReadersMsg = "Number of readers for parallel reading of the input file(s)."
76+
blockSizeMsg = "Desired size of each blob block or page.\n\tCan be an integer byte count or integer suffixed with B, KB, MB, or GB.\n\tFor page blobs the value must be a multiple of 512 bytes."
77+
verboseMsg = "Diplay verbose output for debugging."
78+
quietModeMsg = "Quiet mode, no progress information is written to the stdout.\n\tErrors, warnings and final summary still are written."
79+
computeBlockMD5Msg = "Computes the MD5 for the block and includes the value in the block request."
80+
httpTimeoutMsg = "HTTP client timeout in seconds."
81+
accountNameMsg = "Storage account name (e.g. mystorage).\n\tCan also be specified via the " + storageAccountNameEnvVar + " environment variable."
82+
accountKeyMsg = "Storage account key string.\n\tCan also be specified via the " + storageAccountKeyEnvVar + " environment variable."
83+
dupcheckLevelMsg = "Desired level of effort to detect duplicate data to minimize upload size.\n\tMust be one of " + transfer.DupeCheckLevelStr
84+
transferDefMsg = "Defines the type of source and target in the transfer.\n\tMust be one of:\n\tfile-blockblob, file-pageblob, http-blockblob, http-pageblob, blob-file,\n\tpageblock-file (alias of blob-file), blockblob-file (alias of blob-file)\n\tor http-file."
85+
)
86+
87+
flag.Usage = func() {
88+
util.PrintUsageDefaults("f", "file", "", fileMsg)
89+
util.PrintUsageDefaults("n", "name", "", nameMsg)
90+
util.PrintUsageDefaults("c", "container_name", "", containerNameMsg)
91+
util.PrintUsageDefaults("g", "concurrent_workers", strconv.Itoa(defaultNumberOfWorkers), concurrentWorkersMsg)
92+
util.PrintUsageDefaults("r", "concurrent_readers", strconv.Itoa(defaultNumberOfReaders), concurrentReadersMsg)
93+
util.PrintUsageDefaults("b", "block_size", blockSizeStr, blockSizeMsg)
94+
util.PrintUsageDefaults("v", "verbose", "false", verboseMsg)
95+
util.PrintUsageDefaults("q", "quiet_mode", "false", quietModeMsg)
96+
util.PrintUsageDefaults("m", "compute_blockmd5", "false", computeBlockMD5Msg)
97+
util.PrintUsageDefaults("s", "http_timeout", strconv.Itoa(util.HTTPClientTimeout), httpTimeoutMsg)
98+
util.PrintUsageDefaults("a", "account_name", "", accountNameMsg)
99+
util.PrintUsageDefaults("k", "account_key", "", accountKeyMsg)
100+
util.PrintUsageDefaults("d", "dup_check_level", dedupeLevelOptStr, dupcheckLevelMsg)
101+
util.PrintUsageDefaults("t", "transfer_definition", string(defaultTransferDef), transferDefMsg)
102+
}
103+
104+
util.StringListVarAlias(&sourceURIs, "f", "file", "", fileMsg)
105+
util.StringListVarAlias(&blobNames, "n", "name", "", nameMsg)
106+
util.StringVarAlias(&containerName, "c", "container_name", "", containerNameMsg)
107+
util.IntVarAlias(&numberOfWorkers, "g", "concurrent_workers", defaultNumberOfWorkers, concurrentWorkersMsg)
108+
util.IntVarAlias(&numberOfReaders, "r", "concurrent_readers", defaultNumberOfReaders, concurrentReadersMsg)
109+
util.StringVarAlias(&blockSizeStr, "b", "block_size", blockSizeStr, blockSizeMsg)
110+
util.BoolVarAlias(&util.Verbose, "v", "verbose", false, verboseMsg)
111+
util.BoolVarAlias(&quietMode, "q", "quiet_mode", false, quietModeMsg)
112+
util.BoolVarAlias(&calculateMD5, "m", "compute_blockmd5", false, computeBlockMD5Msg)
113+
util.IntVarAlias(&util.HTTPClientTimeout, "s", "http_timeout", util.HTTPClientTimeout, httpTimeoutMsg)
114+
util.StringVarAlias(&storageAccountName, "a", "account_name", "", accountNameMsg)
115+
util.StringVarAlias(&storageAccountKey, "k", "account_key", "", accountKeyMsg)
116+
util.StringVarAlias(&dedupeLevelOptStr, "d", "dup_check_level", dedupeLevelOptStr, dupcheckLevelMsg)
117+
util.StringVarAlias(&transferDefStr, "t", "transfer_definition", string(defaultTransferDef), transferDefMsg)
118+
83119
}
84120

85121
var dataTransferred uint64
@@ -151,7 +187,7 @@ func isSourceHTTP() bool {
151187

152188
url, err := url.Parse(sourceURIs[0])
153189

154-
return err != nil || strings.ToLower(url.Scheme) == "http" || strings.ToLower(url.Scheme) == "https"
190+
return err == nil && (strings.ToLower(url.Scheme) == "http" || strings.ToLower(url.Scheme) == "https")
155191
}
156192

157193
func getPipelines() (pipeline.SourcePipeline, pipeline.TargetPipeline) {

util/util.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"flag"
55
"fmt"
66
"log"
7+
"os"
78
"regexp"
89
"strconv"
910
"strings"
@@ -119,6 +120,15 @@ func StringVarAlias(varPtr *string, shortflag string, longflag string, defaultVa
119120
flag.StringVar(varPtr, longflag, defaultVal, "")
120121
}
121122

123+
//PrintUsageDefaults print commandline usage options
124+
func PrintUsageDefaults(shortflag string, longflag string, defaultVal string, description string) {
125+
defaultMsg := ""
126+
if defaultVal != "" {
127+
defaultMsg = fmt.Sprintf("\n\tDefault value: %v", defaultVal)
128+
}
129+
fmt.Fprintln(os.Stderr, fmt.Sprintf("-%v, --%v :\n\t%v%v", shortflag, longflag, description, defaultMsg))
130+
}
131+
122132
//ListFlag TODO
123133
type ListFlag []string
124134

0 commit comments

Comments
 (0)