Ejemplo n.º 1
0
// shareSetColor sets colors share sub-commands.
func shareSetColor() {
	// Additional command speific theme customization.
	console.SetColor("Share", color.New(color.FgGreen, color.Bold))
	console.SetColor("Expires", color.New(color.FgRed, color.Bold))
	console.SetColor("URL", color.New(color.FgCyan, color.Bold))
	console.SetColor("File", color.New(color.FgRed, color.Bold))
}
Ejemplo n.º 2
0
// 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."))
}
Ejemplo n.º 3
0
// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
	// Additional command speific theme customization.
	console.SetColor("File", color.New(color.FgWhite))
	console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
	console.SetColor("Size", color.New(color.FgYellow))
	console.SetColor("Time", color.New(color.FgGreen))

	// check 'ls' cli arguments
	checkListSyntax(ctx)

	args := ctx.Args()
	isIncomplete := ctx.Bool("incomplete")

	// mimic operating system tool behavior
	if globalMimicFlag && !ctx.Args().Present() {
		args = []string{"."}
	}

	targetURLs, err := args2URLs(args.Head())
	fatalIf(err.Trace(args...), "One or more unknown URL types passed.")
	for _, targetURL := range targetURLs {
		// if recursive strip off the "..."
		var clnt client.Client
		clnt, err = url2Client(stripRecursiveURL(targetURL))
		fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")

		err = doList(clnt, isURLRecursive(targetURL), isIncomplete)
		fatalIf(err.Trace(clnt.GetURL().String()), "Unable to list target ‘"+clnt.GetURL().String()+"’.")
	}
}
Ejemplo n.º 4
0
// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) {
	// Additional command speific theme customization.
	console.SetColor("File", color.New(color.FgWhite))
	console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
	console.SetColor("Size", color.New(color.FgYellow))
	console.SetColor("Time", color.New(color.FgGreen))

	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'ls' cli arguments.
	checkListSyntax(ctx)

	// Set command flags from context.
	isRecursive := ctx.Bool("recursive")
	isIncomplete := ctx.Bool("incomplete")

	args := ctx.Args()
	// mimic operating system tool behavior.
	if !ctx.Args().Present() {
		args = []string{"."}
	}

	for _, targetURL := range args {
		var clnt client.Client
		clnt, err := newClient(targetURL)
		fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")

		err = doList(clnt, isRecursive, isIncomplete)
		if err != nil {
			errorIf(err.Trace(clnt.GetURL().String()), "Unable to list target ‘"+clnt.GetURL().String()+"’.")
			continue
		}
	}
}
Ejemplo n.º 5
0
Archivo: share.go Proyecto: fwessels/mc
// shareSetColor sets colors share sub-commands.
func shareSetColor() {
	// Additional command speific theme customization.
	console.SetColor("URL", color.New(color.FgWhite, color.Bold))
	console.SetColor("Expire", color.New(color.FgCyan))
	console.SetColor("Content-type", color.New(color.FgBlue))
	console.SetColor("Share", color.New(color.FgGreen))
	console.SetColor("File", color.New(color.FgRed, color.Bold))

}
Ejemplo n.º 6
0
// mainList - is a handler for mc ls command
func mainList(ctx *cli.Context) error {
	// Additional command specific theme customization.
	console.SetColor("File", color.New(color.Bold))
	console.SetColor("Dir", color.New(color.FgCyan, color.Bold))
	console.SetColor("Size", color.New(color.FgYellow))
	console.SetColor("Time", color.New(color.FgGreen))

	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'ls' cli arguments.
	checkListSyntax(ctx)

	// Set command flags from context.
	isRecursive := ctx.Bool("recursive")
	isIncomplete := ctx.Bool("incomplete")

	args := ctx.Args()
	// mimic operating system tool behavior.
	if !ctx.Args().Present() {
		args = []string{"."}
	}

	var cErr error
	for _, targetURL := range args {
		var clnt Client
		clnt, err := newClient(targetURL)
		fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")

		var st *clientContent
		if st, err = clnt.Stat(isIncomplete); err != nil {
			switch err.ToGoError().(type) {
			case BucketNameEmpty:
			// For aliases like ``mc ls s3`` it's acceptable to receive BucketNameEmpty error.
			// Nothing to do.
			default:
				fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
			}
		} else if st.Type.IsDir() {
			if !strings.HasSuffix(targetURL, string(clnt.GetURL().Separator)) {
				targetURL = targetURL + string(clnt.GetURL().Separator)
			}
			clnt, err = newClient(targetURL)
			fatalIf(err.Trace(targetURL), "Unable to initialize target ‘"+targetURL+"’.")
		}
		if e := doList(clnt, isRecursive, isIncomplete); e != nil {
			cErr = e
		}
	}
	return cErr
}
Ejemplo n.º 7
0
func mainMirror(ctx *cli.Context) {
	checkMirrorSyntax(ctx)

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

	var e error
	session := newSessionV3()
	session.Header.CommandType = "mirror"
	session.Header.RootPath, e = os.Getwd()
	if e != nil {
		session.Delete()
		fatalIf(probe.NewError(e), "Unable to get current working folder.")
	}

	// If force flag is set save it with in session
	session.Header.CommandBoolFlag.Key = "force"
	session.Header.CommandBoolFlag.Value = ctx.Bool("force")

	// extract URLs.
	var err *probe.Error
	session.Header.CommandArgs, err = args2URLs(ctx.Args())
	if err != nil {
		session.Delete()
		fatalIf(err.Trace(ctx.Args()...), fmt.Sprintf("One or more unknown argument types found in ‘%s’.", ctx.Args()))
	}

	doMirrorSession(session)
	session.Delete()
}
Ejemplo n.º 8
0
// mainCopy is the entry point for cp command.
func mainCopy(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'copy' cli arguments.
	checkCopySyntax(ctx)

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

	session := newSessionV6()
	session.Header.CommandType = "cp"
	session.Header.CommandBoolFlags["recursive"] = ctx.Bool("recursive")

	var e error
	if session.Header.RootPath, e = os.Getwd(); e != nil {
		session.Delete()
		fatalIf(probe.NewError(e), "Unable to get current working folder.")
	}

	// extract URLs.
	session.Header.CommandArgs = ctx.Args()
	doCopySession(session)
	session.Delete()
}
Ejemplo n.º 9
0
// mainMakeBucket is entry point for mb command.
func mainMakeBucket(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'mb' cli arguments.
	checkMakeBucketSyntax(ctx)

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

	for _, targetURL := range ctx.Args() {
		// Instantiate client for URL.
		clnt, err := newClient(targetURL)
		fatalIf(err.Trace(targetURL), "Invalid target ‘"+targetURL+"’.")

		// Make bucket.
		err = clnt.MakeBucket()
		// Upon error print error and continue.
		if err != nil {
			errorIf(err.Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.")
			continue
		}

		// Successfully created a bucket.
		printMsg(makeBucketMessage{Status: "success", Bucket: targetURL})
	}
}
Ejemplo n.º 10
0
func mainEventsAdd(ctx *cli.Context) error {
	console.SetColor("Events", color.New(color.FgGreen, color.Bold))

	setGlobalsFromContext(ctx)
	checkEventsAddSyntax(ctx)

	args := ctx.Args()
	path := args[0]
	arn := args[1]

	events := strings.Split(ctx.String("events"), ",")
	prefix := ctx.String("prefix")
	suffix := ctx.String("suffix")

	client, err := newClient(path)
	if err != nil {
		fatalIf(err.Trace(), "Cannot parse the provided url.")
	}

	s3Client, ok := client.(*s3Client)
	if !ok {
		fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
	}

	err = s3Client.AddNotificationConfig(arn, events, prefix, suffix)
	fatalIf(err, "Cannot enable notification on the specified bucket.")
	printMsg(eventsAddMessage{
		ARN:    arn,
		Events: events,
		Prefix: prefix,
		Suffix: suffix,
	})

	return nil
}
Ejemplo n.º 11
0
// Main entry point for mirror command.
func mainMirror(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'mirror' cli arguments.
	checkMirrorSyntax(ctx)

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

	var e error
	session := newSessionV6()
	session.Header.CommandType = "mirror"
	session.Header.RootPath, e = os.Getwd()
	if e != nil {
		session.Delete()
		fatalIf(probe.NewError(e), "Unable to get current working folder.")
	}

	// Set command flags from context.
	isForce := ctx.Bool("force")
	session.Header.CommandBoolFlags["force"] = isForce

	// extract URLs.
	session.Header.CommandArgs = ctx.Args()
	doMirrorSession(session)
	session.Delete()
}
Ejemplo n.º 12
0
func mainEventsRemove(ctx *cli.Context) error {
	console.SetColor("Events", color.New(color.FgGreen, color.Bold))

	setGlobalsFromContext(ctx)
	checkEventsRemoveSyntax(ctx)

	args := ctx.Args()
	path := args.Get(0)

	arn := ""
	if len(args) == 2 {
		arn = args.Get(1)
	}

	client, err := newClient(path)
	if err != nil {
		fatalIf(err.Trace(), "Cannot parse the provided url.")
	}

	s3Client, ok := client.(*s3Client)
	if !ok {
		fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
	}

	err = s3Client.RemoveNotificationConfig(arn)
	fatalIf(err, "Cannot enable notification on the specified bucket.")
	printMsg(eventsRemoveMessage{ARN: arn})

	return nil
}
Ejemplo n.º 13
0
// main for rm command.
func mainRm(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'rm' cli arguments.
	checkRmSyntax(ctx)

	// rm specific flags.
	isForce := ctx.Bool("force")
	isIncomplete := ctx.Bool("incomplete")
	isRecursive := ctx.Bool("recursive")
	isFake := ctx.Bool("fake")

	// Set color.
	console.SetColor("Remove", color.New(color.FgGreen, color.Bold))

	// Support multiple targets.
	for _, url := range ctx.Args() {
		targetAlias, targetURL, _ := mustExpandAlias(url)
		if isRecursive && isForce {
			rmAll(targetAlias, targetURL, isRecursive, isIncomplete, isFake)
		} else {
			if err := rm(targetAlias, targetURL, isIncomplete, isFake); err != nil {
				errorIf(err.Trace(url), "Unable to remove ‘"+url+"’.")
				continue
			}
			printMsg(rmMessage{Status: "success", URL: url})
		}
	}
}
Ejemplo n.º 14
0
func mainVersion(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

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

	verMsg := versionMessage{}
	verMsg.CommitID = mcCommitID
	verMsg.ReleaseTag = mcReleaseTag
	verMsg.Version.Value = mcVersion
	verMsg.Version.Format = "RFC3339"

	printMsg(verMsg)
}
Ejemplo n.º 15
0
// newProgressBar - instantiate a pbBar.
func newProgressBar(total int64) *barSend {
	// Progress bar speific theme customization.
	console.SetColor("Bar", color.New(color.FgGreen, color.Bold))

	cmdCh := make(chan barMsg)
	finishCh := make(chan bool)
	go func(total int64, cmdCh <-chan barMsg, finishCh chan<- bool) {
		var started bool
		var totalBytesRead int64 // total amounts of bytes read
		bar := pb.New64(total)
		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 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
			}
		}
	}(total, cmdCh, finishCh)
	return &barSend{cmdCh, finishCh}
}
Ejemplo n.º 16
0
// mainDiff main for 'diff'.
func mainDiff(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'diff' cli arguments.
	checkDiffSyntax(ctx)

	// Additional command specific 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))

	URLs := ctx.Args()
	firstURL := URLs[0]
	secondURL := URLs[1]

	doDiffMain(firstURL, secondURL)
}
Ejemplo n.º 17
0
func mainConfigAlias(ctx *cli.Context) {
	checkConfigAliasSyntax(ctx)

	// Additional customization speific to each command.
	console.SetColor("Alias", color.New(color.FgCyan, color.Bold))
	console.SetColor("AliasMessage", color.New(color.FgGreen, color.Bold))
	console.SetColor("URL", color.New(color.FgWhite, color.Bold))

	arg := ctx.Args().First()
	tailArgs := ctx.Args().Tail()

	switch strings.TrimSpace(arg) {
	case "add":
		addAlias(tailArgs.Get(0), tailArgs.Get(1))
	case "remove":
		removeAlias(tailArgs.Get(0))
	case "list":
		listAliases()
	}
}
Ejemplo n.º 18
0
func mainConfigHost(ctx *cli.Context) {
	checkConfigHostSyntax(ctx)

	// Additional command speific theme customization.
	console.SetColor("Host", color.New(color.FgCyan, color.Bold))
	console.SetColor("API", color.New(color.FgYellow, color.Bold))
	console.SetColor("HostMessage", color.New(color.FgGreen, color.Bold))
	console.SetColor("AccessKeyID", color.New(color.FgBlue, color.Bold))
	console.SetColor("SecretAccessKey", color.New(color.FgRed, color.Bold))

	arg := ctx.Args().First()
	tailArgs := ctx.Args().Tail()

	switch strings.TrimSpace(arg) {
	case "add":
		addHost(tailArgs.Get(0), tailArgs.Get(1), tailArgs.Get(2), tailArgs.Get(3))
	case "remove":
		removeHost(tailArgs.Get(0))
	case "list":
		listHosts()
	}
}
Ejemplo n.º 19
0
func mainEventsList(ctx *cli.Context) error {
	console.SetColor("ARN", color.New(color.FgGreen, color.Bold))
	console.SetColor("Events", color.New(color.FgCyan, color.Bold))
	console.SetColor("Filter", color.New(color.Bold))

	setGlobalsFromContext(ctx)
	checkEventsListSyntax(ctx)

	args := ctx.Args()
	path := args[0]
	arn := ""
	if len(args) > 1 {
		arn = args[1]
	}

	client, err := newClient(path)
	if err != nil {
		fatalIf(err.Trace(), "Cannot parse the provided url.")
	}

	s3Client, ok := client.(*s3Client)
	if !ok {
		fatalIf(errDummy().Trace(), "The provided url doesn't point to a S3 server.")
	}

	configs, err := s3Client.ListNotificationConfigs(arn)
	fatalIf(err, "Cannot enable notification on the specified bucket.")

	for _, config := range configs {
		printMsg(eventsListMessage{Events: config.Events,
			Prefix: config.Prefix,
			Suffix: config.Suffix,
			Arn:    config.Arn,
			ID:     config.ID})
	}

	return nil
}
Ejemplo n.º 20
0
// main entry point for update command.
func mainUpdate(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

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

	// Check for update.
	if ctx.Bool("experimental") {
		getReleaseUpdate(mcUpdateExperimentalURL)
	} else {
		getReleaseUpdate(mcUpdateStableURL)
	}
}
Ejemplo n.º 21
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
}
Ejemplo n.º 22
0
// main for update command.
func mainUpdate(ctx *cli.Context) {
	// check input arguments
	checkUpdateSyntax(ctx)

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

	arg := strings.TrimSpace(ctx.Args().First())
	switch arg {
	case "release":
		getReleaseUpdate()
	case "experimental":
		getExperimentalUpdate()
	}
}
Ejemplo n.º 23
0
// main for rm command.
func mainRm(ctx *cli.Context) {
	checkRmSyntax(ctx)

	// rm specific flags.
	isForce := ctx.Bool("force")
	isIncomplete := ctx.Bool("incomplete")

	// Set color.
	console.SetColor("Remove", color.New(color.FgGreen, color.Bold))

	// Parse args.
	URLs, err := args2URLs(ctx.Args())
	fatalIf(err.Trace(ctx.Args()...), "Unable to parse arguments.")

	// Support multiple targets.
	for _, url := range URLs {
		if isURLRecursive(url) && isForce {
			url := stripRecursiveURL(url)
			removeTopFolder := false

			// find if the URL is dir or not.
			_, content, err := url2Stat(url)
			fatalIf(err.Trace(url), "Unable to stat ‘"+url+"’.")

			if content.Type.IsDir() {
				/* Determine whether to remove the top folder or only its
				contents. If the URL does not end with a separator, then
				include the top folder as well, otherwise not. */
				u := client.NewURL(url)
				if !strings.HasSuffix(url, string(u.Separator)) {
					// Add separator at the end to remove all its contents.
					url = url + string(u.Separator)
					// Remember to remove the top most folder.
					removeTopFolder = true
				}
			}
			// Remove contents of this folder.
			rmAll(url, isIncomplete)
			if removeTopFolder {
				// Remove top folder as well.
				rm(url, isIncomplete)
			}

		} else {
			rm(url, isIncomplete)
		}
	}
}
Ejemplo n.º 24
0
func mainAccess(ctx *cli.Context) {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'access' cli arguments.
	checkAccessSyntax(ctx)

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

	switch ctx.Args().First() {
	case "set":
		perms := accessPerms(ctx.Args().Tail().First())
		URLs := ctx.Args().Tail().Tail()
		for _, targetURL := range URLs {
			err := doSetAccess(targetURL, perms)
			// Upon error, print and continue.
			if err != nil {
				errorIf(err.Trace(targetURL, string(perms)),
					"Unable to set access permission ‘"+string(perms)+"’ for ‘"+targetURL+"’.")
				continue
			}
			printMsg(accessMessage{
				Status:    "success",
				Operation: "set",
				Bucket:    targetURL,
				Perms:     perms,
			})
		}
	case "get":
		URLs := ctx.Args().Tail()
		for _, targetURL := range URLs {
			perms, err := doGetAccess(targetURL)
			if err != nil {
				errorIf(err.Trace(targetURL), "Unable to get access permission for ‘"+targetURL+"’.")
				continue
			}
			printMsg(accessMessage{
				Status:    "success",
				Operation: "get",
				Bucket:    targetURL,
				Perms:     perms,
			})
		}
	}
}
Ejemplo n.º 25
0
// main entry point for update command.
func mainUpdate(ctx *cli.Context) error {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

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

	var updateMsg updateMessage
	var errMsg string
	var err *probe.Error
	// Check for update.
	if ctx.Bool("experimental") {
		updateMsg, errMsg, err = getReleaseUpdate(mcUpdateExperimentalURL)
	} else {
		updateMsg, errMsg, err = getReleaseUpdate(mcUpdateStableURL)
	}
	fatalIf(err, errMsg)
	printMsg(updateMsg)
	return nil
}
Ejemplo n.º 26
0
// mainMakeBucket is entry point for mb command.
func mainMakeBucket(ctx *cli.Context) {
	checkMakeBucketSyntax(ctx)

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

	config := mustGetMcConfig()
	for _, arg := range ctx.Args() {
		targetURL := getAliasURL(arg, config.Aliases)

		// Instantiate client for URL.
		clnt, err := url2Client(targetURL)
		fatalIf(err.Trace(targetURL), "Invalid target ‘"+targetURL+"’.")

		// Make bucket.
		fatalIf(clnt.MakeBucket().Trace(), "Unable to make bucket ‘"+targetURL+"’.")

		// Successfully created a bucket.
		printMsg(makeBucketMessage{Status: "success", Bucket: targetURL})
	}
}
Ejemplo n.º 27
0
// main for rm command.
func mainRm(ctx *cli.Context) error {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'rm' cli arguments.
	checkRmSyntax(ctx)

	// rm specific flags.
	isIncomplete := ctx.Bool("incomplete")
	isRecursive := ctx.Bool("recursive")
	isFake := ctx.Bool("fake")
	isStdin := ctx.Bool("stdin")
	older := ctx.Int("older-than")

	// Set color.
	console.SetColor("Remove", color.New(color.FgGreen, color.Bold))

	// Support multiple targets.
	for _, url := range ctx.Args() {
		if isRecursive {
			return removeRecursive(url, isIncomplete, isFake, older)
		} // else {
		return removeSingle(url, isIncomplete, isFake, older)
	}

	if !isStdin {
		return nil
	}

	scanner := bufio.NewScanner(os.Stdin)
	for scanner.Scan() {
		url := scanner.Text()
		if isRecursive {
			return removeRecursive(url, isIncomplete, isFake, older)
		} // else {
		return removeSingle(url, isIncomplete, isFake, older)
	}
	return nil
}
Ejemplo n.º 28
0
// Main entry point for mirror command.
func mainMirror(ctx *cli.Context) error {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'mirror' cli arguments.
	checkMirrorSyntax(ctx)

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

	session := newSessionV8()
	session.Header.CommandType = "mirror"

	if v, err := os.Getwd(); err == nil {
		session.Header.RootPath = v
	} else {
		session.Delete()
		fatalIf(probe.NewError(err), "Unable to get current working folder.")
	}

	// Set command flags from context.
	session.Header.CommandBoolFlags["force"] = ctx.Bool("force")
	session.Header.CommandBoolFlags["fake"] = ctx.Bool("fake")
	session.Header.CommandBoolFlags["watch"] = ctx.Bool("watch")
	session.Header.CommandBoolFlags["remove"] = ctx.Bool("remove")

	// extract URLs.
	session.Header.CommandArgs = ctx.Args()

	ms := newMirrorSession(session)

	// Mirroring.
	ms.mirror()

	// delete will be run when terminating normally,
	ms.Delete()

	return nil
}
Ejemplo n.º 29
0
// mainMakeBucket is entry point for mb command.
func mainMakeBucket(ctx *cli.Context) error {
	// Set global flags from context.
	setGlobalsFromContext(ctx)

	// check 'mb' cli arguments.
	checkMakeBucketSyntax(ctx)

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

	// Save region.
	region := ctx.String("region")

	var cErr error
	for i := range ctx.Args() {
		targetURL := ctx.Args().Get(i)
		// Instantiate client for URL.
		clnt, err := newClient(targetURL)
		if err != nil {
			errorIf(err.Trace(targetURL), "Invalid target ‘"+targetURL+"’.")
			cErr = exitStatus(globalErrorExitStatus)
			continue
		}

		// Make bucket.
		err = clnt.MakeBucket(region)
		if err != nil {
			errorIf(err.Trace(targetURL), "Unable to make bucket ‘"+targetURL+"’.")
			cErr = exitStatus(globalErrorExitStatus)
			continue
		}

		// Successfully created a bucket.
		printMsg(makeBucketMessage{Status: "success", Bucket: targetURL})
	}
	return cErr
}
Ejemplo n.º 30
0
func mainAccess(ctx *cli.Context) {
	checkAccessSyntax(ctx)

	// Additional command speific theme customization.
	console.SetColor("Access", color.New(color.FgGreen, color.Bold))
	config := mustGetMcConfig()

	switch ctx.Args().Get(0) {
	case "set":
		perms := accessPerms(ctx.Args().Tail().Get(0))
		for _, arg := range ctx.Args().Tail().Tail() {
			targetURL := getAliasURL(arg, config.Aliases)

			fatalIf(doSetAccess(targetURL, perms).Trace(targetURL, string(perms)), "Unable to set access permission ‘"+string(perms)+"’ for ‘"+targetURL+"’.")

			printMsg(accessMessage{
				Operation: "set",
				Status:    "success",
				Bucket:    targetURL,
				Perms:     perms,
			})
		}
	case "get":
		for _, arg := range ctx.Args().Tail() {
			targetURL := getAliasURL(arg, config.Aliases)
			perms, err := doGetAccess(targetURL)
			fatalIf(err.Trace(targetURL), "Unable to get access permission for ‘"+targetURL+"’.")

			printMsg(accessMessage{
				Operation: "get",
				Status:    "success",
				Bucket:    targetURL,
				Perms:     perms,
			})
		}
	}
}