Example #1
0
func main() {
	allItems := getItems()

	failed := false
	for _, i := range allItems {
		for _, el := range i.list {
			if err := os.Remove(el); err != nil {
				if os.IsNotExist(err) {
					continue
				}
				common.Warn("Failed to remove %s %q: %v", i.kind, el, err)
				failed = true
				if infos, err := ioutil.ReadDir(el); err == nil {
					var contents []string
					for _, fi := range infos {
						contents = append(contents, fi.Name())
					}
					common.Warn("  Contents of the directory: %s", strings.Join(contents, ", "))
				}
			}
		}
	}
	if failed {
		os.Exit(1)
	}
}
Example #2
0
// globGetArgs parses given parameters and returns a target, a suffix
// and a list of files.
func globGetArgs(args []string) globArgs {
	f, target := standardFlags(globCmd)
	suffix := f.String("suffix", "", "File suffix (example: .go)")
	globbingMode := f.String("glob-mode", "all", "Which files to glob (normal, dot-files, all [default])")
	filesMode := f.String("mode", "args", "How to get files, either 'filelist' mode or 'args' [default]")
	filelist := f.String("filelist", "", "For filelist mode, read all the files from this file")
	mapTo := []string{}
	mapToWrapper := common.StringSliceWrapper{Slice: &mapTo}
	f.Var(&mapToWrapper, "map-to", "Map contents of filelist to this directory, can be used multiple times")

	f.Parse(args)
	if *target == "" {
		common.Die("--target parameter must be specified and cannot be empty")
	}
	mode := globModeFromString(*globbingMode)
	switch *filesMode {
	case "filelist":
		if *filelist == "" {
			common.Die("--filelist parameter must be specified and cannot be empty")
		}
		if len(mapTo) < 1 {
			common.Die("--map-to parameter must be specified at least once")
		}
	case "args":
		if *filelist != "" {
			common.Warn("--filelist parameter is ignored in args mode")
		}
		if len(mapTo) > 0 {
			common.Warn("--map-to parameter is ignored in args mode")
		}
	}
	return globArgs{
		target:   *target,
		suffix:   *suffix,
		files:    f.Args(),
		mode:     mode,
		fMode:    *filesMode,
		filelist: *filelist,
		mapTo:    mapTo,
	}
}
Example #3
0
File: main.go Project: matomesc/rkt
func main() {
	depTypes := getAllDepTypes()
	depTypesString := fmt.Sprintf("'%s'", strings.Join(depTypes, "', '"))
	if len(os.Args) < 2 {
		common.Die("Expected a deps type (possible values: %s)", depTypesString)
	}
	depType := os.Args[1]
	cmdArgs := os.Args[2:]
	if f, ok := cmds[depType]; ok {
		fmt.Print(f(cmdArgs))
	} else if depType == "--help" || depType == "-help" {
		common.Warn("Run %s with one of the following commands: %s\nE.g. %s %s --help", appName(), depTypesString, os.Args[0], depTypes[0])
	} else {
		common.Die("Unknown deps type: %q, expected one of %s", depType, depTypesString)
	}
}
Example #4
0
File: main.go Project: NeilW/rkt
func main() {
	allItems := getItems()

	failed := false
	for _, i := range allItems {
		for _, el := range i.list {
			if err := os.Remove(el); err != nil {
				if os.IsNotExist(err) {
					continue
				}
				common.Warn("Failed to remove %s %q: %v", i.kind, el, err)
				failed = true
			}
		}
	}
	if failed {
		os.Exit(1)
	}
}