예제 #1
0
파일: rm-main.go 프로젝트: balamurugana/mc
// 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
}