From b51fb32054dc35299413eae0429c0118006f29a8 Mon Sep 17 00:00:00 2001 From: Remco Verhoef Date: Fri, 12 Aug 2016 00:29:04 +0200 Subject: [PATCH] Refacture structure proposal. (#1793) --- .gitignore | 4 +- Makefile | 7 + access-perms.go => command/access-perms.go | 2 +- .../accounting-reader.go | 2 +- .../api_handlers_test.go | 2 +- .../build-constants.go | 2 +- cat-main.go => command/cat-main.go | 2 +- client-errors.go => command/client-errors.go | 2 +- client-fs.go => command/client-fs.go | 2 +- .../client-fs_test.go | 2 +- .../client-s3-trace_v2.go | 2 +- .../client-s3-trace_v4.go | 2 +- client-s3.go => command/client-s3.go | 2 +- .../client-s3_test.go | 2 +- client-url.go => command/client-url.go | 2 +- .../client-url_test.go | 2 +- client.go => command/client.go | 2 +- .../common-methods.go | 2 +- config-fix.go => command/config-fix.go | 2 +- .../config-host-main.go | 2 +- config-main.go => command/config-main.go | 2 +- .../config-migrate.go | 2 +- config-old.go => command/config-old.go | 2 +- config-utils.go => command/config-utils.go | 2 +- config-v8.go => command/config-v8.go | 2 +- .../config-validate.go | 2 +- config.go => command/config.go | 2 +- cp-main.go => command/cp-main.go | 2 +- cp-url-syntax.go => command/cp-url-syntax.go | 2 +- cp-url.go => command/cp-url.go | 2 +- .../damerau-levenshtein.go | 2 +- diff-main.go => command/diff-main.go | 2 +- difference.go => command/difference.go | 2 +- error.go => command/error.go | 2 +- flags.go => command/flags.go | 2 +- fs-pathutils.go => command/fs-pathutils.go | 2 +- .../fs-pathutils_window.go | 2 +- globals.go => command/globals.go | 2 +- ls-main.go => command/ls-main.go | 2 +- ls.go => command/ls.go | 2 +- ls_test.go => command/ls_test.go | 2 +- command/main.go | 268 ++++++++++++++++++ mb-main.go => command/mb-main.go | 2 +- mc_test.go => command/mc_test.go | 2 +- mirror-main.go => command/mirror-main.go | 2 +- mirror-url.go => command/mirror-url.go | 2 +- notifier.go => command/notifier.go | 2 +- pipe-main.go => command/pipe-main.go | 2 +- policy-main.go => command/policy-main.go | 2 +- print.go => command/print.go | 2 +- progress-bar.go => command/progress-bar.go | 2 +- rm-main.go => command/rm-main.go | 2 +- .../runtime-checks.go | 2 +- scan-bar.go => command/scan-bar.go | 2 +- session-main.go => command/session-main.go | 2 +- .../session-migrate.go | 2 +- session-old.go => command/session-old.go | 2 +- session-v7.go => command/session-v7.go | 2 +- session.go => command/session.go | 2 +- session_test.go => command/session_test.go | 2 +- share-db-v1.go => command/share-db-v1.go | 2 +- .../share-download-main.go | 2 +- .../share-list-main.go | 2 +- share-main.go => command/share-main.go | 2 +- .../share-upload-main.go | 2 +- share.go => command/share.go | 2 +- signals.go => command/signals.go | 2 +- time.go => command/time.go | 2 +- trie.go => command/trie.go | 2 +- typed-errors.go => command/typed-errors.go | 2 +- update-main.go => command/update-main.go | 2 +- utils.go => command/utils.go | 2 +- version-main.go => command/version-main.go | 2 +- version_test.go => command/version_test.go | 2 +- main.go | 247 +--------------- 75 files changed, 350 insertions(+), 318 deletions(-) rename access-perms.go => command/access-perms.go (98%) rename accounting-reader.go => command/accounting-reader.go (99%) rename api_handlers_test.go => command/api_handlers_test.go (99%) rename build-constants.go => command/build-constants.go (98%) rename cat-main.go => command/cat-main.go (99%) rename client-errors.go => command/client-errors.go (99%) rename client-fs.go => command/client-fs.go (99%) rename client-fs_test.go => command/client-fs_test.go (99%) rename client-s3-trace_v2.go => command/client-s3-trace_v2.go (99%) rename client-s3-trace_v4.go => command/client-s3-trace_v4.go (99%) rename client-s3.go => command/client-s3.go (99%) rename client-s3_test.go => command/client-s3_test.go (99%) rename client-url.go => command/client-url.go (99%) rename client-url_test.go => command/client-url_test.go (99%) rename client.go => command/client.go (99%) rename common-methods.go => command/common-methods.go (99%) rename config-fix.go => command/config-fix.go (99%) rename config-host-main.go => command/config-host-main.go (99%) rename config-main.go => command/config-main.go (99%) rename config-migrate.go => command/config-migrate.go (99%) rename config-old.go => command/config-old.go (99%) rename config-utils.go => command/config-utils.go (99%) rename config-v8.go => command/config-v8.go (99%) rename config-validate.go => command/config-validate.go (99%) rename config.go => command/config.go (99%) rename cp-main.go => command/cp-main.go (99%) rename cp-url-syntax.go => command/cp-url-syntax.go (99%) rename cp-url.go => command/cp-url.go (99%) rename damerau-levenshtein.go => command/damerau-levenshtein.go (99%) rename diff-main.go => command/diff-main.go (99%) rename difference.go => command/difference.go (99%) rename error.go => command/error.go (99%) rename flags.go => command/flags.go (98%) rename fs-pathutils.go => command/fs-pathutils.go (97%) rename fs-pathutils_window.go => command/fs-pathutils_window.go (98%) rename globals.go => command/globals.go (99%) rename ls-main.go => command/ls-main.go (99%) rename ls.go => command/ls.go (99%) rename ls_test.go => command/ls_test.go (97%) create mode 100644 command/main.go rename mb-main.go => command/mb-main.go (99%) rename mc_test.go => command/mc_test.go (99%) rename mirror-main.go => command/mirror-main.go (99%) rename mirror-url.go => command/mirror-url.go (99%) rename notifier.go => command/notifier.go (99%) rename pipe-main.go => command/pipe-main.go (99%) rename policy-main.go => command/policy-main.go (99%) rename print.go => command/print.go (98%) rename progress-bar.go => command/progress-bar.go (99%) rename rm-main.go => command/rm-main.go (99%) rename runtime-checks.go => command/runtime-checks.go (98%) rename scan-bar.go => command/scan-bar.go (99%) rename session-main.go => command/session-main.go (99%) rename session-migrate.go => command/session-migrate.go (99%) rename session-old.go => command/session-old.go (99%) rename session-v7.go => command/session-v7.go (99%) rename session.go => command/session.go (99%) rename session_test.go => command/session_test.go (99%) rename share-db-v1.go => command/share-db-v1.go (99%) rename share-download-main.go => command/share-download-main.go (99%) rename share-list-main.go => command/share-list-main.go (99%) rename share-main.go => command/share-main.go (99%) rename share-upload-main.go => command/share-upload-main.go (99%) rename share.go => command/share.go (99%) rename signals.go => command/signals.go (98%) rename time.go => command/time.go (99%) rename trie.go => command/trie.go (99%) rename typed-errors.go => command/typed-errors.go (99%) rename update-main.go => command/update-main.go (99%) rename utils.go => command/utils.go (98%) rename version-main.go => command/version-main.go (99%) rename version_test.go => command/version_test.go (97%) diff --git a/.gitignore b/.gitignore index 959621de..607c3b2d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ cover.out -mc +./mc *~ *.test release -experimental \ No newline at end of file +experimental diff --git a/Makefile b/Makefile index b4af0ed6..f70cd4be 100644 --- a/Makefile +++ b/Makefile @@ -19,26 +19,32 @@ verifiers: vet fmt lint cyclo deadcode spelling vet: @echo "Running $@:" @GO15VENDOREXPERIMENT=1 go tool vet -all *.go + @GO15VENDOREXPERIMENT=1 go tool vet -all ./command @GO15VENDOREXPERIMENT=1 go tool vet -all ./pkg @GO15VENDOREXPERIMENT=1 go tool vet -shadow=true *.go + @GO15VENDOREXPERIMENT=1 go tool vet -shadow=true ./command @GO15VENDOREXPERIMENT=1 go tool vet -shadow=true ./pkg spelling: @GO15VENDOREXPERIMENT=1 ${GOPATH}/bin/misspell *.go + @GO15VENDOREXPERIMENT=1 ${GOPATH}/bin/misspell command/**/* @GO15VENDOREXPERIMENT=1 ${GOPATH}/bin/misspell pkg/**/* fmt: @echo "Running $@:" @GO15VENDOREXPERIMENT=1 gofmt -s -l *.go + @GO15VENDOREXPERIMENT=1 gofmt -s -l command @GO15VENDOREXPERIMENT=1 gofmt -s -l pkg lint: @echo "Running $@:" @GO15VENDOREXPERIMENT=1 $(GOPATH)/bin/golint . + @GO15VENDOREXPERIMENT=1 $(GOPATH)/bin/golint github.com/minio/mc/command @GO15VENDOREXPERIMENT=1 $(GOPATH)/bin/golint github.com/minio/mc/pkg... cyclo: @echo "Running $@:" @GO15VENDOREXPERIMENT=1 $(GOPATH)/bin/gocyclo -over 40 *.go + @GO15VENDOREXPERIMENT=1 $(GOPATH)/bin/gocyclo -over 40 command @GO15VENDOREXPERIMENT=1 $(GOPATH)/bin/gocyclo -over 40 pkg deadcode: @@ -51,6 +57,7 @@ build: getdeps verifiers test: getdeps verifiers @echo "Running all testing:" @GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) ./ + @GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/mc/command @GO15VENDOREXPERIMENT=1 go test $(GOFLAGS) github.com/minio/mc/pkg... gomake-all: build diff --git a/access-perms.go b/command/access-perms.go similarity index 98% rename from access-perms.go rename to command/access-perms.go index df8eec4b..4f9850f0 100644 --- a/access-perms.go +++ b/command/access-perms.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command // isValidAccessPERM - is provided access perm string supported. func (b accessPerms) isValidAccessPERM() bool { diff --git a/accounting-reader.go b/command/accounting-reader.go similarity index 99% rename from accounting-reader.go rename to command/accounting-reader.go index d247ab63..277cb094 100644 --- a/accounting-reader.go +++ b/command/accounting-reader.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "sync" diff --git a/api_handlers_test.go b/command/api_handlers_test.go similarity index 99% rename from api_handlers_test.go rename to command/api_handlers_test.go index 3174fe0f..cf5e4623 100644 --- a/api_handlers_test.go +++ b/command/api_handlers_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bytes" diff --git a/build-constants.go b/command/build-constants.go similarity index 98% rename from build-constants.go rename to command/build-constants.go index 0f5eb122..3ca2c452 100644 --- a/build-constants.go +++ b/command/build-constants.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command var ( // mcVersion - version time.RFC3339. diff --git a/cat-main.go b/command/cat-main.go similarity index 99% rename from cat-main.go rename to command/cat-main.go index 94351bee..5999a5d6 100644 --- a/cat-main.go +++ b/command/cat-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "errors" diff --git a/client-errors.go b/command/client-errors.go similarity index 99% rename from client-errors.go rename to command/client-errors.go index 66ea6cac..8a40bf3b 100644 --- a/client-errors.go +++ b/command/client-errors.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import "fmt" diff --git a/client-fs.go b/command/client-fs.go similarity index 99% rename from client-fs.go rename to command/client-fs.go index df95ec9f..745beec7 100644 --- a/client-fs.go +++ b/command/client-fs.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "io" diff --git a/client-fs_test.go b/command/client-fs_test.go similarity index 99% rename from client-fs_test.go rename to command/client-fs_test.go index 69e25bce..c076c70f 100644 --- a/client-fs_test.go +++ b/command/client-fs_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bytes" diff --git a/client-s3-trace_v2.go b/command/client-s3-trace_v2.go similarity index 99% rename from client-s3-trace_v2.go rename to command/client-s3-trace_v2.go index 1f67f2ac..1b08cdbc 100644 --- a/client-s3-trace_v2.go +++ b/command/client-s3-trace_v2.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bytes" diff --git a/client-s3-trace_v4.go b/command/client-s3-trace_v4.go similarity index 99% rename from client-s3-trace_v4.go rename to command/client-s3-trace_v4.go index ecf8adec..b2a15127 100644 --- a/client-s3-trace_v4.go +++ b/command/client-s3-trace_v4.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bytes" diff --git a/client-s3.go b/command/client-s3.go similarity index 99% rename from client-s3.go rename to command/client-s3.go index aa504e7c..ebda29d6 100644 --- a/client-s3.go +++ b/command/client-s3.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "errors" diff --git a/client-s3_test.go b/command/client-s3_test.go similarity index 99% rename from client-s3_test.go rename to command/client-s3_test.go index e93a0497..8cc09497 100644 --- a/client-s3_test.go +++ b/command/client-s3_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command // bucketHandler is an http.Handler that verifies bucket responses and validates incoming requests import ( diff --git a/client-url.go b/command/client-url.go similarity index 99% rename from client-url.go rename to command/client-url.go index b0612bac..f8d19dd4 100644 --- a/client-url.go +++ b/command/client-url.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bytes" diff --git a/client-url_test.go b/command/client-url_test.go similarity index 99% rename from client-url_test.go rename to command/client-url_test.go index 79411939..8c670a57 100644 --- a/client-url_test.go +++ b/command/client-url_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import . "gopkg.in/check.v1" diff --git a/client.go b/command/client.go similarity index 99% rename from client.go rename to command/client.go index 3c9bcc46..227ea39c 100644 --- a/client.go +++ b/command/client.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "io" diff --git a/common-methods.go b/command/common-methods.go similarity index 99% rename from common-methods.go rename to command/common-methods.go index 792cdc08..7f0d06bf 100644 --- a/common-methods.go +++ b/command/common-methods.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "io" diff --git a/config-fix.go b/command/config-fix.go similarity index 99% rename from config-fix.go rename to command/config-fix.go index b405b238..feaf8b63 100644 --- a/config-fix.go +++ b/command/config-fix.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/config-host-main.go b/command/config-host-main.go similarity index 99% rename from config-host-main.go rename to command/config-host-main.go index 0cb86bf9..1985d67a 100644 --- a/config-host-main.go +++ b/command/config-host-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/config-main.go b/command/config-main.go similarity index 99% rename from config-main.go rename to command/config-main.go index c0972506..b02bce24 100644 --- a/config-main.go +++ b/command/config-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import "github.com/minio/cli" diff --git a/config-migrate.go b/command/config-migrate.go similarity index 99% rename from config-migrate.go rename to command/config-migrate.go index b8fd2a68..c0b9db3d 100644 --- a/config-migrate.go +++ b/command/config-migrate.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/config-old.go b/command/config-old.go similarity index 99% rename from config-old.go rename to command/config-old.go index 5a97be09..f9b057aa 100644 --- a/config-old.go +++ b/command/config-old.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command /////////////////// Config V1 /////////////////// type hostConfigV1 struct { diff --git a/config-utils.go b/command/config-utils.go similarity index 99% rename from config-utils.go rename to command/config-utils.go index 26a352e4..8385d690 100644 --- a/config-utils.go +++ b/command/config-utils.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "regexp" diff --git a/config-v8.go b/command/config-v8.go similarity index 99% rename from config-v8.go rename to command/config-v8.go index b57cbe71..256cf9c8 100644 --- a/config-v8.go +++ b/command/config-v8.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "sync" diff --git a/config-validate.go b/command/config-validate.go similarity index 99% rename from config-validate.go rename to command/config-validate.go index 42d859e5..aefcb7ab 100644 --- a/config-validate.go +++ b/command/config-validate.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bytes" diff --git a/config.go b/command/config.go similarity index 99% rename from config.go rename to command/config.go index 1d4ff80e..be13e3e7 100644 --- a/config.go +++ b/command/config.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/cp-main.go b/command/cp-main.go similarity index 99% rename from cp-main.go rename to command/cp-main.go index 2de49482..c402c7c9 100644 --- a/cp-main.go +++ b/command/cp-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bufio" diff --git a/cp-url-syntax.go b/command/cp-url-syntax.go similarity index 99% rename from cp-url-syntax.go rename to command/cp-url-syntax.go index 550a42f3..70201b9e 100644 --- a/cp-url-syntax.go +++ b/command/cp-url-syntax.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/cp-url.go b/command/cp-url.go similarity index 99% rename from cp-url.go rename to command/cp-url.go index 138915a2..47c6b100 100644 --- a/cp-url.go +++ b/command/cp-url.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "path/filepath" diff --git a/damerau-levenshtein.go b/command/damerau-levenshtein.go similarity index 99% rename from damerau-levenshtein.go rename to command/damerau-levenshtein.go index a01361a5..bce228eb 100644 --- a/damerau-levenshtein.go +++ b/command/damerau-levenshtein.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "math" diff --git a/diff-main.go b/command/diff-main.go similarity index 99% rename from diff-main.go rename to command/diff-main.go index 977ae4f7..f96c7fb7 100644 --- a/diff-main.go +++ b/command/diff-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/difference.go b/command/difference.go similarity index 99% rename from difference.go rename to command/difference.go index 132afbe8..73e0c693 100644 --- a/difference.go +++ b/command/difference.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/error.go b/command/error.go similarity index 99% rename from error.go rename to command/error.go index b11c5f29..958623f6 100644 --- a/error.go +++ b/command/error.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/flags.go b/command/flags.go similarity index 98% rename from flags.go rename to command/flags.go index d9c826f5..7c219a91 100644 --- a/flags.go +++ b/command/flags.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import "github.com/minio/cli" diff --git a/fs-pathutils.go b/command/fs-pathutils.go similarity index 97% rename from fs-pathutils.go rename to command/fs-pathutils.go index 411d9c75..519c1bed 100644 --- a/fs-pathutils.go +++ b/command/fs-pathutils.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package main +package command func normalizePath(path string) string { return path diff --git a/fs-pathutils_window.go b/command/fs-pathutils_window.go similarity index 98% rename from fs-pathutils_window.go rename to command/fs-pathutils_window.go index 68aab579..0d24cb70 100644 --- a/fs-pathutils_window.go +++ b/command/fs-pathutils_window.go @@ -16,7 +16,7 @@ * limitations under the License. */ -package main +package command import ( "path/filepath" diff --git a/globals.go b/command/globals.go similarity index 99% rename from globals.go rename to command/globals.go index 83dcf7a0..de151ada 100644 --- a/globals.go +++ b/command/globals.go @@ -15,7 +15,7 @@ */ // This package contains all the global variables and constants. ONLY TO BE ACCESSED VIA GET/SET FUNCTIONS. -package main +package command import ( "github.com/minio/cli" diff --git a/ls-main.go b/command/ls-main.go similarity index 99% rename from ls-main.go rename to command/ls-main.go index cfadb78f..09768314 100644 --- a/ls-main.go +++ b/command/ls-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "strings" diff --git a/ls.go b/command/ls.go similarity index 99% rename from ls.go rename to command/ls.go index fe109899..9f8db4e3 100644 --- a/ls.go +++ b/command/ls.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/ls_test.go b/command/ls_test.go similarity index 97% rename from ls_test.go rename to command/ls_test.go index c05aa9c2..01b64fd9 100644 --- a/ls_test.go +++ b/command/ls_test.go @@ -14,4 +14,4 @@ * limitations under the License. */ -package main +package command diff --git a/command/main.go b/command/main.go new file mode 100644 index 00000000..9851c1cd --- /dev/null +++ b/command/main.go @@ -0,0 +1,268 @@ +/* + * Minio Client (C) 2014, 2015 Minio, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package command + +import ( + "bytes" + "fmt" + "os" + "path/filepath" + "runtime" + "sort" + "strconv" + + "github.com/cheggaaa/pb" + "github.com/minio/cli" + "github.com/minio/mc/pkg/console" + "github.com/minio/minio/pkg/probe" + "github.com/pkg/profile" +) + +var ( + // global flags for mc. + mcFlags = []cli.Flag{ + cli.BoolFlag{ + Name: "help, h", + Usage: "Show help.", + }, + } +) + +// Help template for mc +var mcHelpTemplate = `NAME: + {{.Name}} - {{.Usage}} + +USAGE: + {{.Name}} {{if .Flags}}[FLAGS] {{end}}COMMAND{{if .Flags}} [COMMAND FLAGS | -h]{{end}} [ARGUMENTS...] + +COMMANDS: + {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} + {{end}}{{if .Flags}} +GLOBAL FLAGS: + {{range .Flags}}{{.}} + {{end}}{{end}} +VERSION: + ` + mcVersion + + `{{ "\n"}}{{range $key, $value := ExtraInfo}} +{{$key}}: + {{$value}} +{{end}}` + +// Main starts mc application +func Main() { + // Enable profiling supported modes are [cpu, mem, block]. + // ``MC_PROFILER`` supported options are [cpu, mem, block]. + switch os.Getenv("MC_PROFILER") { + case "cpu": + defer profile.Start(profile.CPUProfile, profile.ProfilePath(mustGetProfileDir())).Stop() + case "mem": + defer profile.Start(profile.MemProfile, profile.ProfilePath(mustGetProfileDir())).Stop() + case "block": + defer profile.Start(profile.BlockProfile, profile.ProfilePath(mustGetProfileDir())).Stop() + } + + probe.Init() // Set project's root source path. + probe.SetAppInfo("Release-Tag", mcReleaseTag) + probe.SetAppInfo("Commit", mcShortCommitID) + + app := registerApp() + app.Before = registerBefore + app.ExtraInfo = func() map[string]string { + if _, e := pb.GetTerminalWidth(); e != nil { + globalQuiet = true + } + if globalDebug { + return getSystemData() + } + return make(map[string]string) + } + + app.RunAndExitOnError() +} + +// Function invoked when invalid command is passed. +func commandNotFound(ctx *cli.Context, command string) { + msg := fmt.Sprintf("‘%s’ is not a mc command. See ‘mc --help’.", command) + closestCommands := findClosestCommands(command) + if len(closestCommands) > 0 { + msg += fmt.Sprintf("\n\nDid you mean one of these?\n") + if len(closestCommands) == 1 { + cmd := closestCommands[0] + msg += fmt.Sprintf(" ‘%s’", cmd) + } else { + for _, cmd := range closestCommands { + msg += fmt.Sprintf(" ‘%s’\n", cmd) + } + } + } + fatalIf(errDummy().Trace(), msg) +} + +// Check for sane config environment early on and gracefully report. +func checkConfig() { + // Refresh the config once. + loadMcConfig = loadMcConfigFactory() + // Ensures config file is sane. + config, err := loadMcConfig() + // Verify if the path is accesible before validating the config + fatalIf(err.Trace(mustGetMcConfigPath()), "Unable to access configuration file.") + + // Validate and print error messges + ok, errMsgs := validateConfigFile(config) + if !ok { + var errorMsg bytes.Buffer + for index, errMsg := range errMsgs { + // Print atmost 10 errors + if index > 10 { + break + } + errorMsg.WriteString(errMsg + "\n") + } + console.Fatalln(errorMsg.String()) + } +} + +func migrate() { + // Fix broken config files if any. + fixConfig() + + // Migrate config files if any. + migrateConfig() + + // Migrate session files if any. + migrateSession() + + // Migrate shared urls if any. + migrateShare() +} + +// Get os/arch/platform specific information. +// Returns a map of current os/arch/platform/memstats. +func getSystemData() map[string]string { + host, e := os.Hostname() + fatalIf(probe.NewError(e), "Unable to determine the hostname.") + + memstats := &runtime.MemStats{} + runtime.ReadMemStats(memstats) + mem := fmt.Sprintf("Used: %s | Allocated: %s | UsedHeap: %s | AllocatedHeap: %s", + pb.Format(int64(memstats.Alloc)).To(pb.U_BYTES), + pb.Format(int64(memstats.TotalAlloc)).To(pb.U_BYTES), + pb.Format(int64(memstats.HeapAlloc)).To(pb.U_BYTES), + pb.Format(int64(memstats.HeapSys)).To(pb.U_BYTES)) + platform := fmt.Sprintf("Host: %s | OS: %s | Arch: %s", host, runtime.GOOS, runtime.GOARCH) + goruntime := fmt.Sprintf("Version: %s | CPUs: %s", runtime.Version(), strconv.Itoa(runtime.NumCPU())) + return map[string]string{ + "PLATFORM": platform, + "RUNTIME": goruntime, + "MEM": mem, + } +} + +// initMC - initialize 'mc'. +func initMC() { + // Check if mc config exists. + if !isMcConfigExists() { + err := saveMcConfig(newMcConfig()) + fatalIf(err.Trace(), "Unable to save new mc config.") + + console.Infoln("Configuration written to ‘" + mustGetMcConfigPath() + "’. Please update your access credentials.") + } + + // Check if mc session folder exists. + if !isSessionDirExists() { + fatalIf(createSessionDir().Trace(), "Unable to create session config folder.") + } + + // Check if mc share folder exists. + if !isShareDirExists() { + initShareConfig() + } +} + +func registerBefore(ctx *cli.Context) error { + // Check if mc was compiled using a supported version of Golang. + checkGoVersion() + + // Set the config folder. + setMcConfigDir(ctx.GlobalString("config-folder")) + + // Migrate any old version of config / state files to newer format. + migrate() + + // Initialize default config files. + initMC() + + // Set global flags. + setGlobalsFromContext(ctx) + + // Check if config can be read. + checkConfig() + + return nil +} + +// findClosestCommands to match a given string with commands trie tree. +func findClosestCommands(command string) []string { + var closestCommands []string + for _, value := range commandsTree.PrefixMatch(command) { + closestCommands = append(closestCommands, value.(string)) + } + sort.Strings(closestCommands) + // Suggest other close commands - allow missed, wrongly added and even transposed characters + for _, value := range commandsTree.walk(commandsTree.root) { + if sort.SearchStrings(closestCommands, value.(string)) < len(closestCommands) { + continue + } + // 2 is arbitrary and represents the max allowed number of typed errors + if DamerauLevenshteinDistance(command, value.(string)) < 2 { + closestCommands = append(closestCommands, value.(string)) + } + } + return closestCommands +} + +func registerApp() *cli.App { + // Register all the commands (refer flags.go) + registerCmd(lsCmd) // List contents of a bucket. + registerCmd(mbCmd) // Make a bucket. + registerCmd(catCmd) // Display contents of a file. + registerCmd(pipeCmd) // Write contents of stdin to a file. + registerCmd(shareCmd) // Share documents via URL. + registerCmd(cpCmd) // Copy objects and files from multiple sources to single destination. + registerCmd(mirrorCmd) // Mirror objects and files from single source to multiple destinations. + registerCmd(diffCmd) // Computer differences between two files or folders. + registerCmd(rmCmd) // Remove a file or bucket + registerCmd(policyCmd) // Set policy permissions. + registerCmd(sessionCmd) // Manage sessions for copy and mirror. + registerCmd(configCmd) // Configure minio client. + registerCmd(updateCmd) // Check for new software updates. + registerCmd(versionCmd) // Print version. + + app := cli.NewApp() + app.Usage = "Minio Client for cloud storage and filesystems." + app.Commands = commands + app.Author = "Minio.io" + app.Flags = append(mcFlags, globalFlags...) + app.CustomAppHelpTemplate = mcHelpTemplate + app.CommandNotFound = commandNotFound // handler function declared above. + return app +} + +// mustGetProfilePath must get location that the profile will be written to. +func mustGetProfileDir() string { + return filepath.Join(mustGetMcConfigDir(), globalProfileDir) +} diff --git a/mb-main.go b/command/mb-main.go similarity index 99% rename from mb-main.go rename to command/mb-main.go index a8bd921f..817d7bce 100644 --- a/mb-main.go +++ b/command/mb-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/mc_test.go b/command/mc_test.go similarity index 99% rename from mc_test.go rename to command/mc_test.go index c365316b..d702daf2 100644 --- a/mc_test.go +++ b/command/mc_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "path/filepath" diff --git a/mirror-main.go b/command/mirror-main.go similarity index 99% rename from mirror-main.go rename to command/mirror-main.go index 3043f490..cb9e190c 100644 --- a/mirror-main.go +++ b/command/mirror-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bufio" diff --git a/mirror-url.go b/command/mirror-url.go similarity index 99% rename from mirror-url.go rename to command/mirror-url.go index 3e6cf315..3ad5c917 100644 --- a/mirror-url.go +++ b/command/mirror-url.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/notifier.go b/command/notifier.go similarity index 99% rename from notifier.go rename to command/notifier.go index cdec1b0a..0d398ab2 100644 --- a/notifier.go +++ b/command/notifier.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/pipe-main.go b/command/pipe-main.go similarity index 99% rename from pipe-main.go rename to command/pipe-main.go index 1ba8b3d0..69c498b5 100644 --- a/pipe-main.go +++ b/command/pipe-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/policy-main.go b/command/policy-main.go similarity index 99% rename from policy-main.go rename to command/policy-main.go index 6917398d..116024bd 100644 --- a/policy-main.go +++ b/command/policy-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/print.go b/command/print.go similarity index 98% rename from print.go rename to command/print.go index 49b3207c..8c54d0ec 100644 --- a/print.go +++ b/command/print.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import "github.com/minio/mc/pkg/console" diff --git a/progress-bar.go b/command/progress-bar.go similarity index 99% rename from progress-bar.go rename to command/progress-bar.go index a10f8062..f3e5d920 100644 --- a/progress-bar.go +++ b/command/progress-bar.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "io" diff --git a/rm-main.go b/command/rm-main.go similarity index 99% rename from rm-main.go rename to command/rm-main.go index bf0c65a2..0856bef5 100644 --- a/rm-main.go +++ b/command/rm-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/runtime-checks.go b/command/runtime-checks.go similarity index 98% rename from runtime-checks.go rename to command/runtime-checks.go index 2aada2d4..ed665e6d 100644 --- a/runtime-checks.go +++ b/command/runtime-checks.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/scan-bar.go b/command/scan-bar.go similarity index 99% rename from scan-bar.go rename to command/scan-bar.go index 4d5d2976..bbd5448f 100644 --- a/scan-bar.go +++ b/command/scan-bar.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/session-main.go b/command/session-main.go similarity index 99% rename from session-main.go rename to command/session-main.go index ad1aa488..bb0143d2 100644 --- a/session-main.go +++ b/command/session-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/session-migrate.go b/command/session-migrate.go similarity index 99% rename from session-migrate.go rename to command/session-migrate.go index d6325e7c..315d1a7f 100644 --- a/session-migrate.go +++ b/command/session-migrate.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/session-old.go b/command/session-old.go similarity index 99% rename from session-old.go rename to command/session-old.go index 4fb4fe33..0e9d30fa 100644 --- a/session-old.go +++ b/command/session-old.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/session-v7.go b/command/session-v7.go similarity index 99% rename from session-v7.go rename to command/session-v7.go index f2e662fb..ca3f6e58 100644 --- a/session-v7.go +++ b/command/session-v7.go @@ -16,7 +16,7 @@ // Session V2 - Version 2 stores session header and session data in // two separate files. Session data contains fully prepared URL list. -package main +package command import ( "encoding/json" diff --git a/session.go b/command/session.go similarity index 99% rename from session.go rename to command/session.go index 4159115c..d7c07691 100644 --- a/session.go +++ b/command/session.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/session_test.go b/command/session_test.go similarity index 99% rename from session_test.go rename to command/session_test.go index f50e430e..4923f112 100644 --- a/session_test.go +++ b/command/session_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/share-db-v1.go b/command/share-db-v1.go similarity index 99% rename from share-db-v1.go rename to command/share-db-v1.go index f1ce5fad..e79db47c 100644 --- a/share-db-v1.go +++ b/command/share-db-v1.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/share-download-main.go b/command/share-download-main.go similarity index 99% rename from share-download-main.go rename to command/share-download-main.go index 920320ed..afa3a36d 100644 --- a/share-download-main.go +++ b/command/share-download-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "time" diff --git a/share-list-main.go b/command/share-list-main.go similarity index 99% rename from share-list-main.go rename to command/share-list-main.go index 77159087..abfdc4c2 100644 --- a/share-list-main.go +++ b/command/share-list-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/share-main.go b/command/share-main.go similarity index 99% rename from share-main.go rename to command/share-main.go index 41b0840a..04a46aaf 100644 --- a/share-main.go +++ b/command/share-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/share-upload-main.go b/command/share-upload-main.go similarity index 99% rename from share-upload-main.go rename to command/share-upload-main.go index 385beea9..60cf3396 100644 --- a/share-upload-main.go +++ b/command/share-upload-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/share.go b/command/share.go similarity index 99% rename from share.go rename to command/share.go index fb9efa60..be52012d 100644 --- a/share.go +++ b/command/share.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "bytes" diff --git a/signals.go b/command/signals.go similarity index 98% rename from signals.go rename to command/signals.go index e7e8b02b..55a3fa72 100644 --- a/signals.go +++ b/command/signals.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "os" diff --git a/time.go b/command/time.go similarity index 99% rename from time.go rename to command/time.go index b99af6e2..66cea8bb 100644 --- a/time.go +++ b/command/time.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "fmt" diff --git a/trie.go b/command/trie.go similarity index 99% rename from trie.go rename to command/trie.go index 7a37bf40..f8a4b8f9 100644 --- a/trie.go +++ b/command/trie.go @@ -15,7 +15,7 @@ */ // This file implements a simple trie tree to be used for 'mc' cli commands. -package main +package command // This package borrows idea from - https://godoc.org/golang.org/x/text/internal/triegen. diff --git a/typed-errors.go b/command/typed-errors.go similarity index 99% rename from typed-errors.go rename to command/typed-errors.go index ba000195..5330e331 100644 --- a/typed-errors.go +++ b/command/typed-errors.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "errors" diff --git a/update-main.go b/command/update-main.go similarity index 99% rename from update-main.go rename to command/update-main.go index 1fc7eab9..086fb5c5 100644 --- a/update-main.go +++ b/command/update-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/utils.go b/command/utils.go similarity index 98% rename from utils.go rename to command/utils.go index 2d910ed3..4bb4476d 100644 --- a/utils.go +++ b/command/utils.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "math/rand" diff --git a/version-main.go b/command/version-main.go similarity index 99% rename from version-main.go rename to command/version-main.go index f056f923..cffa0909 100644 --- a/version-main.go +++ b/command/version-main.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "encoding/json" diff --git a/version_test.go b/command/version_test.go similarity index 97% rename from version_test.go rename to command/version_test.go index f6d83504..14e5eed0 100644 --- a/version_test.go +++ b/command/version_test.go @@ -14,7 +14,7 @@ * limitations under the License. */ -package main +package command import ( "net/http" diff --git a/main.go b/main.go index babb2c12..96ce11d5 100644 --- a/main.go +++ b/main.go @@ -17,252 +17,9 @@ package main import ( - "bytes" - "fmt" - "os" - "path/filepath" - "runtime" - "sort" - "strconv" - - "github.com/cheggaaa/pb" - "github.com/minio/cli" - "github.com/minio/mc/pkg/console" - "github.com/minio/minio/pkg/probe" - "github.com/pkg/profile" + command "github.com/minio/mc/command" ) -var ( - // global flags for mc. - mcFlags = []cli.Flag{ - cli.BoolFlag{ - Name: "help, h", - Usage: "Show help.", - }, - } -) - -// Help template for mc -var mcHelpTemplate = `NAME: - {{.Name}} - {{.Usage}} - -USAGE: - {{.Name}} {{if .Flags}}[FLAGS] {{end}}COMMAND{{if .Flags}} [COMMAND FLAGS | -h]{{end}} [ARGUMENTS...] - -COMMANDS: - {{range .Commands}}{{join .Names ", "}}{{ "\t" }}{{.Usage}} - {{end}}{{if .Flags}} -GLOBAL FLAGS: - {{range .Flags}}{{.}} - {{end}}{{end}} -VERSION: - ` + mcVersion + - `{{ "\n"}}{{range $key, $value := ExtraInfo}} -{{$key}}: - {{$value}} -{{end}}` - -// Function invoked when invalid command is passed. -func commandNotFound(ctx *cli.Context, command string) { - msg := fmt.Sprintf("‘%s’ is not a mc command. See ‘mc --help’.", command) - closestCommands := findClosestCommands(command) - if len(closestCommands) > 0 { - msg += fmt.Sprintf("\n\nDid you mean one of these?\n") - if len(closestCommands) == 1 { - cmd := closestCommands[0] - msg += fmt.Sprintf(" ‘%s’", cmd) - } else { - for _, cmd := range closestCommands { - msg += fmt.Sprintf(" ‘%s’\n", cmd) - } - } - } - fatalIf(errDummy().Trace(), msg) -} - -// Check for sane config environment early on and gracefully report. -func checkConfig() { - // Refresh the config once. - loadMcConfig = loadMcConfigFactory() - // Ensures config file is sane. - config, err := loadMcConfig() - // Verify if the path is accesible before validating the config - fatalIf(err.Trace(mustGetMcConfigPath()), "Unable to access configuration file.") - - // Validate and print error messges - ok, errMsgs := validateConfigFile(config) - if !ok { - var errorMsg bytes.Buffer - for index, errMsg := range errMsgs { - // Print atmost 10 errors - if index > 10 { - break - } - errorMsg.WriteString(errMsg + "\n") - } - console.Fatalln(errorMsg.String()) - } -} - -func migrate() { - // Fix broken config files if any. - fixConfig() - - // Migrate config files if any. - migrateConfig() - - // Migrate session files if any. - migrateSession() - - // Migrate shared urls if any. - migrateShare() -} - -// Get os/arch/platform specific information. -// Returns a map of current os/arch/platform/memstats. -func getSystemData() map[string]string { - host, e := os.Hostname() - fatalIf(probe.NewError(e), "Unable to determine the hostname.") - - memstats := &runtime.MemStats{} - runtime.ReadMemStats(memstats) - mem := fmt.Sprintf("Used: %s | Allocated: %s | UsedHeap: %s | AllocatedHeap: %s", - pb.Format(int64(memstats.Alloc)).To(pb.U_BYTES), - pb.Format(int64(memstats.TotalAlloc)).To(pb.U_BYTES), - pb.Format(int64(memstats.HeapAlloc)).To(pb.U_BYTES), - pb.Format(int64(memstats.HeapSys)).To(pb.U_BYTES)) - platform := fmt.Sprintf("Host: %s | OS: %s | Arch: %s", host, runtime.GOOS, runtime.GOARCH) - goruntime := fmt.Sprintf("Version: %s | CPUs: %s", runtime.Version(), strconv.Itoa(runtime.NumCPU())) - return map[string]string{ - "PLATFORM": platform, - "RUNTIME": goruntime, - "MEM": mem, - } -} - -// initMC - initialize 'mc'. -func initMC() { - // Check if mc config exists. - if !isMcConfigExists() { - err := saveMcConfig(newMcConfig()) - fatalIf(err.Trace(), "Unable to save new mc config.") - - console.Infoln("Configuration written to ‘" + mustGetMcConfigPath() + "’. Please update your access credentials.") - } - - // Check if mc session folder exists. - if !isSessionDirExists() { - fatalIf(createSessionDir().Trace(), "Unable to create session config folder.") - } - - // Check if mc share folder exists. - if !isShareDirExists() { - initShareConfig() - } -} - -func registerBefore(ctx *cli.Context) error { - // Check if mc was compiled using a supported version of Golang. - checkGoVersion() - - // Set the config folder. - setMcConfigDir(ctx.GlobalString("config-folder")) - - // Migrate any old version of config / state files to newer format. - migrate() - - // Initialize default config files. - initMC() - - // Set global flags. - setGlobalsFromContext(ctx) - - // Check if config can be read. - checkConfig() - - return nil -} - -// findClosestCommands to match a given string with commands trie tree. -func findClosestCommands(command string) []string { - var closestCommands []string - for _, value := range commandsTree.PrefixMatch(command) { - closestCommands = append(closestCommands, value.(string)) - } - sort.Strings(closestCommands) - // Suggest other close commands - allow missed, wrongly added and even transposed characters - for _, value := range commandsTree.walk(commandsTree.root) { - if sort.SearchStrings(closestCommands, value.(string)) < len(closestCommands) { - continue - } - // 2 is arbitrary and represents the max allowed number of typed errors - if DamerauLevenshteinDistance(command, value.(string)) < 2 { - closestCommands = append(closestCommands, value.(string)) - } - } - return closestCommands -} - -func registerApp() *cli.App { - // Register all the commands (refer flags.go) - registerCmd(lsCmd) // List contents of a bucket. - registerCmd(mbCmd) // Make a bucket. - registerCmd(catCmd) // Display contents of a file. - registerCmd(pipeCmd) // Write contents of stdin to a file. - registerCmd(shareCmd) // Share documents via URL. - registerCmd(cpCmd) // Copy objects and files from multiple sources to single destination. - registerCmd(mirrorCmd) // Mirror objects and files from single source to multiple destinations. - registerCmd(diffCmd) // Computer differences between two files or folders. - registerCmd(rmCmd) // Remove a file or bucket - registerCmd(policyCmd) // Set policy permissions. - registerCmd(sessionCmd) // Manage sessions for copy and mirror. - registerCmd(configCmd) // Configure minio client. - registerCmd(updateCmd) // Check for new software updates. - registerCmd(versionCmd) // Print version. - - app := cli.NewApp() - app.Usage = "Minio Client for cloud storage and filesystems." - app.Commands = commands - app.Author = "Minio.io" - app.Flags = append(mcFlags, globalFlags...) - app.CustomAppHelpTemplate = mcHelpTemplate - app.CommandNotFound = commandNotFound // handler function declared above. - return app -} - -// mustGetProfilePath must get location that the profile will be written to. -func mustGetProfileDir() string { - return filepath.Join(mustGetMcConfigDir(), globalProfileDir) -} - func main() { - // Enable profiling supported modes are [cpu, mem, block]. - // ``MC_PROFILER`` supported options are [cpu, mem, block]. - switch os.Getenv("MC_PROFILER") { - case "cpu": - defer profile.Start(profile.CPUProfile, profile.ProfilePath(mustGetProfileDir())).Stop() - case "mem": - defer profile.Start(profile.MemProfile, profile.ProfilePath(mustGetProfileDir())).Stop() - case "block": - defer profile.Start(profile.BlockProfile, profile.ProfilePath(mustGetProfileDir())).Stop() - } - - probe.Init() // Set project's root source path. - probe.SetAppInfo("Release-Tag", mcReleaseTag) - probe.SetAppInfo("Commit", mcShortCommitID) - - app := registerApp() - app.Before = registerBefore - - app.ExtraInfo = func() map[string]string { - if _, e := pb.GetTerminalWidth(); e != nil { - globalQuiet = true - } - if globalDebug { - return getSystemData() - } - return make(map[string]string) - } - - app.RunAndExitOnError() + command.Main() }