예제 #1
0
파일: version-main.go 프로젝트: zhujo01/mc
func mainVersion(ctx *cli.Context) {
	if ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
	}

	setVersionPalette(ctx.GlobalString("colors"))

	if globalJSONFlag {
		tB, e := json.Marshal(
			struct {
				Version struct {
					Value  string `json:"value"`
					Format string `json:"format"`
				} `json:"version"`
			}{
				Version: struct {
					Value  string `json:"value"`
					Format string `json:"format"`
				}{
					Value:  mcVersion,
					Format: "RFC2616",
				},
			},
		)
		fatalIf(probe.NewError(e), "Unable to construct version string.")
		console.Println(string(tB))
		return
	}
	msg := console.Colorize("Version", fmt.Sprintf("Version: %s\n", mcVersion))
	msg += console.Colorize("Version", fmt.Sprintf("Release-Tag: %s", mcReleaseTag))
	console.Println(msg)
}
예제 #2
0
// String colorized access message
func (s AccessMessage) String() string {
	if s.Operation == "set" {
		return console.Colorize("Access", "Set access permission ‘"+string(s.Perms)+"’ updated successfully for ‘"+s.Bucket+"’")
	}
	if s.Operation == "get" {
		return console.Colorize("Access", "Access permission for ‘"+s.Bucket+"’"+" is ‘"+string(s.Perms)+"’")
	}
	// nothing to print
	return ""
}
예제 #3
0
// String colorized clear session message.
func (c clearSessionMessage) String() string {
	msg := "Session ‘" + c.SessionID + "’"
	var colorizedMsg string
	switch c.Status {
	case "success":
		colorizedMsg = console.Colorize("ClearSession", msg+" cleared successfully.")
	case "forced":
		colorizedMsg = console.Colorize("ClearSession", msg+" cleared forcefully.")
	}
	return colorizedMsg
}
예제 #4
0
func (u watchMessage) String() string {
	msg := console.Colorize("Time", fmt.Sprintf("[%s] ", u.Event.Time))
	if u.Event.Type == EventCreate {
		msg += console.Colorize("Size", fmt.Sprintf("%6s ", humanize.IBytes(uint64(u.Event.Size))))
	} else {
		msg += fmt.Sprintf("%6s ", "")
	}
	msg += console.Colorize("EventType", fmt.Sprintf("%s ", u.Event.Type))
	msg += console.Colorize("ObjectName", fmt.Sprintf("%s", u.Event.Path))
	return msg
}
예제 #5
0
파일: ls.go 프로젝트: akiradeveloper/mc
// String colorized string message
func (c ContentMessage) String() string {
	message := console.Colorize("Time", fmt.Sprintf("[%s] ", c.Time.Format(printDate)))
	message = message + console.Colorize("Size", fmt.Sprintf("%6s ", humanize.IBytes(uint64(c.Size))))
	message = func() string {
		if c.Filetype == "folder" {
			return message + console.Colorize("Dir", fmt.Sprintf("%s", c.Name))
		}
		return message + console.Colorize("File", fmt.Sprintf("%s", c.Name))
	}()
	return message
}
예제 #6
0
// String colorized access message.
func (s policyMessage) String() string {
	if s.Operation == "set" {
		return console.Colorize("Policy",
			"Access permission for ‘"+s.Bucket+"’ is set to ‘"+string(s.Perms)+"’")
	}
	if s.Operation == "get" {
		return console.Colorize("Policy",
			"Access permission for ‘"+s.Bucket+"’"+" is ‘"+string(s.Perms)+"’")
	}
	// nothing to print
	return ""
}
예제 #7
0
파일: diff.go 프로젝트: henrylee2cn/mc
// String colorized diff message
func (d DiffMessage) String() string {
	msg := ""
	switch d.Diff {
	case "only-in-first":
		msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffOnlyInFirst", " - only in first.")
	case "type":
		msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffType", " - differ in type.")
	case "size":
		msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffSize", " - differ in size.")
	default:
		fatalIf(errDummy().Trace(), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.")
	}
	return msg

}
예제 #8
0
// String colorized alias message
func (a AliasMessage) String() string {
	if a.op == "list" {
		message := console.Colorize("Alias", fmt.Sprintf("[%s] <- ", a.Alias))
		message += console.Colorize("URL", fmt.Sprintf("%s", a.URL))
		return message
	}
	if a.op == "remove" {
		return console.Colorize("AliasMessage", "Removed alias ‘"+a.Alias+"’ successfully.")
	}
	if a.op == "add" {
		return console.Colorize("AliasMessage", "Added alias ‘"+a.Alias+"’ successfully.")
	}
	// should never come here
	return ""
}
예제 #9
0
파일: diff-main.go 프로젝트: koolhead17/mc
// mainDiff main for 'diff'.
func mainDiff(ctx *cli.Context) {
	checkDiffSyntax(ctx)

	// Additional command speific theme customization.
	console.SetColor("DiffMessage", color.New(color.FgGreen, color.Bold))
	console.SetColor("DiffOnlyInFirst", color.New(color.FgRed, color.Bold))
	console.SetColor("DiffType", color.New(color.FgYellow, color.Bold))
	console.SetColor("DiffSize", color.New(color.FgMagenta, color.Bold))

	config := mustGetMcConfig()
	firstArg := ctx.Args().First()
	secondArg := ctx.Args().Last()

	firstURL := getAliasURL(firstArg, config.Aliases)
	secondURL := getAliasURL(secondArg, config.Aliases)

	newFirstURL := stripRecursiveURL(firstURL)
	for diff := range doDiffMain(newFirstURL, secondURL, isURLRecursive(firstURL)) {
		if diff.Error != nil {
			// Print in new line and adjust to top so that we don't print over the ongoing scan bar
			if !globalQuietFlag && !globalJSONFlag {
				console.Eraseline()
			}
		}
		fatalIf(diff.Error.Trace(newFirstURL, secondURL), "Failed to diff ‘"+firstURL+"’ and ‘"+secondURL+"’.")
		printMsg(diff)
	}
	// Print in new line and adjust to top so that we don't print over the ongoing scan bar
	if !globalQuietFlag && !globalJSONFlag {
		console.Eraseline()
	}
	console.Println(console.Colorize("DiffMessage", "Done."))
}
예제 #10
0
파일: pb.go 프로젝트: akiradeveloper/mc
// newProgressBar - instantiate a pbBar.
func newProgressBar() barSend {
	console.SetCustomTheme(map[string]*color.Color{
		"Bar": color.New(color.FgGreen, color.Bold),
	})
	cmdCh := make(chan barMsg)
	finishCh := make(chan bool)
	go func(cmdCh <-chan barMsg, finishCh chan<- bool) {
		var started bool
		var totalBytesRead int64 // total amounts of bytes read
		bar := pb.New64(0)
		bar.SetUnits(pb.U_BYTES)
		bar.SetRefreshRate(time.Millisecond * 125)
		bar.NotPrint = true
		bar.ShowSpeed = true
		bar.Callback = func(s string) {
			console.Print(console.Colorize("Bar", "\r"+s))
		}
		switch runtime.GOOS {
		case "linux":
			bar.Format("┃▓█░┃")
			// bar.Format("█▓▒░█")
		case "darwin":
			bar.Format(" ▓ ░ ")
		default:
			bar.Format("[=> ]")
		}
		for msg := range cmdCh {
			switch msg.Op {
			case pbBarSetCaption:
				bar.Prefix(fixateBarCaption(msg.Arg.(string), getFixedWidth(bar.GetWidth(), 18)))
			case pbBarExtend:
				atomic.AddInt64(&bar.Total, msg.Arg.(int64))
			case pbBarProgress:
				if bar.Total > 0 && !started {
					started = true
					bar.Start()
				}
				if msg.Arg.(int64) > 0 {
					totalBytesRead += msg.Arg.(int64)
					bar.Add64(msg.Arg.(int64))
				}
			case pbBarPutError:
				if totalBytesRead > msg.Arg.(int64) {
					bar.Set64(totalBytesRead - msg.Arg.(int64))
				}
			case pbBarGetError:
				if msg.Arg.(int64) > 0 {
					bar.Add64(msg.Arg.(int64))
				}
			case pbBarFinish:
				if started {
					bar.Finish()
				}
				finishCh <- true
				return
			}
		}
	}(cmdCh, finishCh)
	return barSend{cmdCh, finishCh}
}
예제 #11
0
func (u eventsListMessage) String() string {
	msg := console.Colorize("ARN", fmt.Sprintf("%s   ", u.Arn))
	for i, event := range u.Events {
		msg += console.Colorize("Events", event)
		if i != len(u.Events)-1 {
			msg += ","
		}
	}
	msg += console.Colorize("Filter", fmt.Sprintf("   Filter: "))
	if u.Prefix != "" {
		msg += console.Colorize("Filter", fmt.Sprintf("prefix=\"%s\"", u.Prefix))
	}
	if u.Suffix != "" {
		msg += console.Colorize("Filter", fmt.Sprintf("suffix=\"%s\"", u.Suffix))
	}
	return msg
}
예제 #12
0
파일: ls.go 프로젝트: axcoto-lab/mc
// String string printer for Content metadata.
func (c ContentMessage) String() string {
	if !globalJSONFlag {
		message := console.Colorize("Time", fmt.Sprintf("[%s] ", c.Time.Format(printDate)))
		message = message + console.Colorize("Size", fmt.Sprintf("%6s ", humanize.IBytes(uint64(c.Size))))
		message = func() string {
			if c.Filetype == "folder" {
				return message + console.Colorize("Dir", fmt.Sprintf("%s", c.Name))
			}
			return message + console.Colorize("File", fmt.Sprintf("%s", c.Name))
		}()
		return message
	}
	jsonMessageBytes, e := json.Marshal(c)
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(jsonMessageBytes)
}
예제 #13
0
파일: cp-main.go 프로젝트: axcoto-lab/mc
// String string printer for copy message
func (c CopyMessage) String() string {
	if !globalJSONFlag {
		return console.Colorize("Copy", fmt.Sprintf("‘%s’ -> ‘%s’", c.Source, c.Target))
	}
	copyMessageBytes, err := json.Marshal(c)
	fatalIf(probe.NewError(err), "Failed to marshal copy message.")

	return string(copyMessageBytes)
}
예제 #14
0
파일: mb-main.go 프로젝트: axcoto-lab/mc
func (s MakeBucketMessage) String() string {
	if !globalJSONFlag {
		return console.Colorize("MakeBucket", "Bucket created successfully  ‘"+s.Bucket+"’")
	}
	makeBucketJSONBytes, err := json.Marshal(s)
	fatalIf(probe.NewError(err), "Unable to marshal into JSON.")

	return string(makeBucketJSONBytes)
}
예제 #15
0
func (s AccessMessage) String() string {
	if !globalJSONFlag {
		return console.Colorize("Access", "Set access permission ‘"+string(s.Perms)+"’ updated successfully for ‘"+s.Bucket+"’")
	}
	accessJSONBytes, err := json.Marshal(s)
	fatalIf(probe.NewError(err), "Unable to marshal into JSON.")

	return string(accessJSONBytes)
}
예제 #16
0
파일: session-v2.go 프로젝트: axcoto-lab/mc
func (s sessionV2) String() string {
	if !globalJSONFlag {
		message := console.Colorize("SessionID", fmt.Sprintf("%s -> ", s.SessionID))
		message = message + console.Colorize("SessionTime", fmt.Sprintf("[%s]", s.Header.When.Local().Format(printDate)))
		message = message + console.Colorize("Command", fmt.Sprintf(" %s %s", s.Header.CommandType, strings.Join(s.Header.CommandArgs, " ")))
		return message
	}
	sessionMesage := SessionMessage{
		SessionID:   s.SessionID,
		Time:        s.Header.When.Local(),
		CommandType: s.Header.CommandType,
		CommandArgs: s.Header.CommandArgs,
	}
	sessionBytes, e := json.Marshal(sessionMesage)
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(sessionBytes)
}
예제 #17
0
// String string printer for mirror message
func (s MirrorMessage) String() string {
	if !globalJSONFlag {
		return console.Colorize("Mirror", fmt.Sprintf("‘%s’ -> ‘%s’", s.Source, s.Targets))
	}
	mirrorMessageBytes, e := json.Marshal(s)
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(mirrorMessageBytes)
}
예제 #18
0
func (c ClearSessionMessage) String() string {
	if !globalJSONFlag {
		return console.Colorize("ClearSession", "Session ‘"+c.SessionID+"’ cleared successfully")
	}
	clearSessionJSONBytes, err := json.Marshal(c)
	fatalIf(probe.NewError(err), "Unable to marshal into JSON.")

	return string(clearSessionJSONBytes)
}
예제 #19
0
// String string printer for Content metadata
func (a AliasMessage) String() string {
	if !globalJSONFlag {
		if a.op == "list" {
			message := console.Colorize("Alias", fmt.Sprintf("[%s] <- ", a.Alias))
			message += console.Colorize("URL", fmt.Sprintf("%s", a.URL))
			return message
		}
		if a.op == "remove" {
			return console.Colorize("AliasMessage", "Removed alias ‘"+a.Alias+"’ successfully.")
		}
		if a.op == "add" {
			return console.Colorize("AliasMessage", "Added alias ‘"+a.Alias+"’ successfully.")
		}
	}
	jsonMessageBytes, e := json.Marshal(a)
	fatalIf(probe.NewError(e), "Unable to marshal into JSON.")

	return string(jsonMessageBytes)
}
예제 #20
0
파일: status.go 프로젝트: balamurugana/mc
// Finish displays the accounting summary
func (qs *QuietStatus) Finish() {
	accntStat := qs.accounter.Stat()
	cpStatMessage := mirrorStatMessage{
		Total:       accntStat.Total,
		Transferred: accntStat.Transferred,
		Speed:       accntStat.Speed,
	}

	console.Println(console.Colorize("Mirror", cpStatMessage.String()))
}
예제 #21
0
파일: diff.go 프로젝트: axcoto-lab/mc
func (d DiffMessage) String() string {
	if !globalJSONFlag {
		msg := ""
		switch d.Diff {
		case "only-in-first":
			msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffOnlyInFirst", " - only in first.")
		case "type":
			msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffType", " - differ in type.")
		case "size":
			msg = console.Colorize("DiffMessage", "‘"+d.FirstURL+"’"+" and "+"‘"+d.SecondURL+"’") + console.Colorize("DiffSize", " - differ in size.")
		default:
			fatalIf(errDummy().Trace(), "Unhandled difference between ‘"+d.FirstURL+"’ and ‘"+d.SecondURL+"’.")
		}
		return msg
	}
	diffJSONBytes, err := json.Marshal(d)
	fatalIf(probe.NewError(err), "Unable to marshal diff message ‘"+d.FirstURL+"’, ‘"+d.SecondURL+"’ and ‘"+d.Diff+"’.")

	return string(diffJSONBytes)
}
예제 #22
0
파일: share-main.go 프로젝트: dudymas/mc
// String - regular colorized message
func (s ShareMessage) String() string {
	if len(s.DownloadURL) > 0 {
		return console.Colorize("Share", fmt.Sprintf("%s", s.DownloadURL))
	}
	var key string
	URL := client.NewURL(s.Key)
	postURL := URL.Scheme + URL.SchemeSeparator + URL.Host + string(URL.Separator) + s.UploadInfo["bucket"] + " "
	curlCommand := "curl " + postURL
	for k, v := range s.UploadInfo {
		if k == "key" {
			key = v
			continue
		}
		curlCommand = curlCommand + fmt.Sprintf("-F %s=%s ", k, v)
	}
	curlCommand = curlCommand + fmt.Sprintf("-F key=%s ", key) + "-F file=@<FILE> "
	emphasize := console.Colorize("File", "<FILE>")
	curlCommand = strings.Replace(curlCommand, "<FILE>", emphasize, -1)
	return console.Colorize("Share", fmt.Sprintf("%s", curlCommand))
}
예제 #23
0
// doShareList list shared url's
func doShareList() *probe.Error {
	sURLs, err := loadSharedURLsV2()
	if err != nil {
		return err.Trace()
	}
	for i, data := range sURLs.URLs {
		if time.Since(data.Date) > data.Message.Expiry {
			sURLs.URLs = append(sURLs.URLs[:i], sURLs.URLs[i+1:]...)
			continue
		}
		expiry := data.Message.Expiry - time.Since(data.Date)
		if !globalJSONFlag {
			msg := console.Colorize("Share", "Name: ")
			msg += console.Colorize("URL", data.Message.Key+"\n")
			msg += console.Colorize("Share", "Expiry: ")
			msg += console.Colorize("Expires", timeDurationToHumanizedTime(expiry))
			msg += "\n"
			console.Println(msg)
			continue
		}
		shareListBytes, err := json.Marshal(struct {
			Expiry humanizedTime `json:"expiry"`
			URL    string        `json:"url"`
			Key    string        `json:"keyName"`
		}{
			Expiry: timeDurationToHumanizedTime(expiry),
			URL:    data.Message.URL,
			Key:    data.Message.Key,
		})
		if err != nil {
			return probe.NewError(err)
		}
		console.Println(string(shareListBytes))
	}
	if err := saveSharedURLsV2(sURLs); err != nil {
		return err.Trace()
	}
	return nil
}
예제 #24
0
파일: update-main.go 프로젝트: zhujo01/mc
// String colorized update message
func (u UpdateMessage) String() string {
	if u.Update {
		var msg string
		if runtime.GOOS == "windows" {
			msg = "mc.exe cp " + u.Download + " .\\mc.exe"
		} else {
			msg = "mc cp " + u.Download + " ./mc.new; chmod 755 ./mc.new"
		}
		msg, err := colorizeUpdateMessage(msg)
		fatalIf(err.Trace(msg), "Unable to colorize experimental update notification string ‘"+msg+"’.")
		return msg
	}
	return console.Colorize("UpdateMessage", "You are already running the most recent version of ‘mc’.")
}
예제 #25
0
// String colorized update message.
func (u updateMessage) String() string {
	if !u.Update {
		return console.Colorize("Update", "You are already running the most recent version of ‘mc’.")
	}
	var msg string
	if runtime.GOOS == "windows" {
		msg = "Download " + u.Download
	} else {
		msg = "Download " + u.Download
	}
	msg, err := colorizeUpdateMessage(msg)
	fatalIf(err.Trace(msg), "Unable to colorize experimental update notification string ‘"+msg+"’.")
	return msg
}
예제 #26
0
// newProgressBar - instantiate a progress bar.
func newProgressBar(total int64) *progressBar {
	// Progress bar speific theme customization.
	console.SetColor("Bar", color.New(color.FgGreen, color.Bold))

	pgbar := progressBar{}

	// get the new original progress bar.
	bar := pb.New64(total)

	// Set new human friendly print units.
	bar.SetUnits(pb.U_BYTES)

	// Refresh rate for progress bar is set to 125 milliseconds.
	bar.SetRefreshRate(time.Millisecond * 125)

	// Do not print a newline by default handled, it is handled manually.
	bar.NotPrint = true

	// Show current speed is true.
	bar.ShowSpeed = true

	// Custom callback with colorized bar.
	bar.Callback = func(s string) {
		console.Print(console.Colorize("Bar", "\r"+s))
	}

	// Use different unicodes for Linux, OS X and Windows.
	switch runtime.GOOS {
	case "linux":
		// Need to add '\x00' as delimiter for unicode characters.
		bar.Format("┃\x00▓\x00█\x00░\x00┃")
	case "darwin":
		// Need to add '\x00' as delimiter for unicode characters.
		bar.Format(" \x00▓\x00 \x00░\x00 ")
	default:
		// Default to non unicode characters.
		bar.Format("[=> ]")
	}

	// Start the progress bar.
	if bar.Total > 0 {
		bar.Start()
	}

	// Copy for future
	pgbar.ProgressBar = bar

	// Return new progress bar here.
	return &pgbar
}
예제 #27
0
func mainVersion(ctx *cli.Context) {
	if ctx.Args().First() == "help" {
		cli.ShowCommandHelpAndExit(ctx, "version", 1) // last argument is exit code
	}

	// Additional command speific theme customization.
	console.SetColor("Version", color.New(color.FgGreen, color.Bold))

	if globalJSONFlag {
		tB, e := json.Marshal(
			struct {
				CommitID string `json:"commitId"`
				Version  struct {
					Value  string `json:"value"`
					Format string `json:"format"`
				} `json:"version"`
			}{
				CommitID: mcCommitID,
				Version: struct {
					Value  string `json:"value"`
					Format string `json:"format"`
				}{
					Value:  mcVersion,
					Format: "RFC3339",
				},
			},
		)
		fatalIf(probe.NewError(e), "Unable to construct version string.")
		console.Println(string(tB))
		return
	}
	msg := console.Colorize("Version", fmt.Sprintf("Version: %s\n", mcVersion))
	msg += console.Colorize("Version", fmt.Sprintf("Release-Tag: %s\n", mcReleaseTag))
	msg += console.Colorize("Version", fmt.Sprintf("Commit-ID: %s", mcCommitID))
	console.Println(msg)
}
예제 #28
0
func (u UpdateMessage) String() string {
	if !globalJSONFlag {
		if u.Update {
			var msg string
			if runtime.GOOS == "windows" {
				msg = "mc.exe cp " + u.Download + " .\\mc.exe"
			} else {
				msg = "mc cp " + u.Download + " ./mc"
			}
			msg, err := colorizeUpdateMessage(msg)
			fatalIf(err.Trace(msg), "Unable to colorize experimental update notification string ‘"+msg+"’.")
			return msg
		}
		return console.Colorize("UpdateMessage", "You are already running the most recent version of ‘mc’.")
	}
	updateMessageJSONBytes, err := json.Marshal(u)
	fatalIf(probe.NewError(err), "Unable to marshal into JSON.")

	return string(updateMessageJSONBytes)
}
예제 #29
0
// String colorized host message
func (h hostMessage) String() string {
	switch h.op {
	case "list":
		message := console.Colorize("Alias", fmt.Sprintf("%s: ", h.Alias))
		message += console.Colorize("URL", fmt.Sprintf("%s", h.URL))
		if h.AccessKey != "" || h.SecretKey != "" {
			message += " <- " + console.Colorize("AccessKey", fmt.Sprintf(" %s", h.AccessKey))
			message += " | " + console.Colorize("SecretKey", fmt.Sprintf(" %s", h.SecretKey))
			message += " | " + console.Colorize("API", fmt.Sprintf(" %s", h.API))
		}
		return message
	case "remove":
		return console.Colorize("HostMessage", "Removed ‘"+h.Alias+"’ successfully.")
	case "add":
		return console.Colorize("HostMessage", "Added ‘"+h.Alias+"’ successfully.")
	default:
		return ""
	}
}
예제 #30
0
파일: share.go 프로젝트: fwessels/mc
// String - Themefied string message for console printing.
func (s shareMesssage) String() string {
	msg := console.Colorize("URL", fmt.Sprintf("URL: %s\n", s.ObjectURL))
	msg += console.Colorize("Expire", fmt.Sprintf("Expire: %s\n", timeDurationToHumanizedTime(s.TimeLeft)))
	if s.ContentType != "" {
		msg += console.Colorize("Content-type", fmt.Sprintf("Content-Type: %s\n", s.ContentType))
	}

	// Highlight <FILE> specifically. "share upload" sub-commands use this identifier.
	shareURL := strings.Replace(s.ShareURL, "<FILE>", console.Colorize("File", "<FILE>"), 1)
	// Highlight <KEY> specifically for recursive operation.
	shareURL = strings.Replace(shareURL, "<NAME>", console.Colorize("File", "<NAME>"), 1)

	msg += console.Colorize("Share", fmt.Sprintf("Share: %s\n", shareURL))

	return msg
}