// Make a list of source paths and one destination path from the given command line args
779047
func parseSrcDestArgs(g *libkb.GlobalContext, ctx *cli.Context, name string) ([]keybase1.Path, keybase1.Path, error) {
	nargs := len(ctx.Args())

	var srcType, destType keybase1.PathType
	var srcPaths []keybase1.Path
	var destPath keybase1.Path

	if nargs < 2 {
		return srcPaths, destPath, errors.New(name + " requires one or more source arguments and a destination argument")
	}
	for i, src := range ctx.Args() {
		rev := int64(0)
		timeString := ""
		relTimeString := ""
		if i != nargs-1 {
			// All source paths use the same revision.
			rev = int64(ctx.Int("rev"))
			timeString = ctx.String("time")
			relTimeString = getRelTime(ctx)
		}
		argPath, err := makeSimpleFSPathWithArchiveParams(
			src, rev, timeString, relTimeString)
		if err != nil {
			return nil, keybase1.Path{}, err
		}
		tempPathType, err := argPath.PathType()
		if err != nil {
			return srcPaths, destPath, err
		}
		// Make sure all source paths are the same type
		if i == 0 {
			srcType = tempPathType
		} else if i == nargs-1 {
			destPath = argPath
			destType = tempPathType
			break
		} else if tempPathType != srcType {
			return srcPaths, destPath, errors.New(name + " requires all sources to be the same type")
		}
		srcPaths = append(srcPaths, argPath)
	}

	if srcType == keybase1.PathType_LOCAL && destType == keybase1.PathType_LOCAL {
		return srcPaths, destPath, errors.New(name + " requires KBFS source and/or destination")
	}
	return srcPaths, destPath, nil
}
1023183
func NewSourcePathError(path string) error {
	return Error{
		Message:    fmt.Sprintf("Local filesystem source path does not exist: %s", path),
		Details:    nil,
		ErrorCode:  SourcePathError,
		Suggestion: "check the source code path on the local filesystem",
	}
}
625152
func CommandLine() string {
	// We don't use the full path to the tool so that running goagen multiple times doesn't
	// end up creating different command line comments (because of the temporary directory it
	// runs in).
	var param string

	if len(os.Args) > 1 {
		args := make([]string, len(os.Args)-1)
		gopaths := filepath.SplitList(envOr("GOPATH", build.Default.GOPATH))
		for i, a := range os.Args[1:] {
			for _, p := range gopaths {
				p = "=" + p
				if strings.Contains(a, p) {
					args[i] = strings.Replace(a, p, "=$(GOPATH)", 1)
					break
				}
			}
			if args[i] == "" {
				args[i] = a
			}
		}
		param = strings.Join(args, " ")
	}
	rawcmd := filepath.Base(os.Args[0])
	// Remove possible .exe suffix to not create different ouptut just because
	// you ran goagen on Windows.
	rawcmd = strings.TrimSuffix(rawcmd, ".exe")

	cmd := fmt.Sprintf("$ %s %s", rawcmd, param)
	return strings.Replace(cmd, " --", "\n\t--", -1)
}
81498
func (d *SourceFilesystem) MakePathRelative(filename string) string {
	for _, currentPath := range d.Dirnames {
		if strings.HasPrefix(filename, currentPath) {
			return strings.TrimPrefix(filename, currentPath)
		}
	}
	return ""
}
1186591
func (c *Conn) ParseCmdLineArgs(args []string) error {
	// add an empty element 0 -- Ceph treats the array as the actual contents
	// of argv and skips the first element (the executable name)
	argc := C.int(len(args) + 1)
	argv := make([]*C.char, argc)

	// make the first element a string just in case it is ever examined
	argv[0] = C.CString("placeholder")
	defer C.free(unsafe.Pointer(argv[0]))

	for i, arg := range args {
		argv[i+1] = C.CString(arg)
		defer C.free(unsafe.Pointer(argv[i+1]))
	}

	ret := C.rados_conf_parse_argv(c.cluster, argc, &argv[0])
	if ret < 0 {
		return RadosError(int(ret))
	} else {
		return nil
	}
}
1078494
func List(path string) ([]string, error) {
	dest := make([]byte, 1024)
	i, err := syscall.Listxattr(path, dest)
	if err != nil {
		return nil, err
	}

	// If the returned list is empty, return nil instead of []string{""}
	str := string(dest[:i])
	if str == "" {
		return nil, nil
	}

	return strings.Split(strings.TrimRight(str, nilByte), nilByte), nil
}
187046
func (cl *CommandLine) BuildArgs() []string {
	targetArgs := cl.Target.buildArgsForTarget()
	args := make([]string, 0, len(cl.Flags)+1+len(targetArgs)+len(cl.Args))
	for _, flag := range cl.Flags {
		args = append(args, flag.String())
	}

	var flagSeparator []string
	if cl.FlagSeparator {
		flagSeparator = []string{"--"}
	}

	// If our target is specified as a flag, we need to emit it before the flag
	// separator. If our target is specified as a positional argument (e.g.,
	// CommandTarget), we can emit it on either side.
	if !cl.Target.followsFlagSeparator() {
		args = append(args, targetArgs...)
		args = append(args, flagSeparator...)
	} else {
		args = append(args, flagSeparator...)
		args = append(args, targetArgs...)
	}

	args = append(args, cl.Args...)
	return args
}
569406
func pathnames(ts []*tq.Transfer) []string {
	pathnames := make([]string, 0, len(ts))
	for _, t := range ts {
		pathnames = append(pathnames, fmt.Sprintf("pathname=%s", t.Name))
	}

	return pathnames
}
294938
func CommandLineToArgv(commandLine string) ([]string, error) {
	var argc int32

	argsPtr, err := windows.UTF16PtrFromString(commandLine)
	if err != nil {
		return nil, err
	}

	argv, err := windows.CommandLineToArgv(argsPtr, &argc)
	if err != nil {
		return nil, err
	}
	defer windows.LocalFree(windows.Handle(uintptr(unsafe.Pointer(argv))))

	newArgs := make([]string, argc)
	for i, v := range (*argv)[:argc] {
		newArgs[i] = string(windows.UTF16ToString((*v)[:]))
	}

	return newArgs, nil
}
1199648
func GoMainDirs(packages []string, GoCmd string) ([]string, error) {
	args := make([]string, 0, len(packages)+3)
	args = append(args, "list", "-f", "{{.Name}}|{{.ImportPath}}")
	args = append(args, packages...)

	output, err := execGo(GoCmd, nil, "", args...)
	if err != nil {
		return nil, err
	}

	results := make([]string, 0, len(output))
	for _, line := range strings.Split(output, "\n") {
		if line == "" {
			continue
		}

		parts := strings.SplitN(line, "|", 2)
		if len(parts) != 2 {
			log.Printf("Bad line reading packages: %s", line)
			continue
		}

		if parts[0] == "main" {
			results = append(results, parts[1])
		}
	}

	return results, nil
}
480909
func MakeDir(c cookoo.Context, p *cookoo.Params) (interface{}, cookoo.Interrupt) {
	name := p.Get("path", "").(string)
	t := p.Get("ttl", uint64(0)).(uint64)
	ttl := time.Duration(t) * time.Second

	cli := p.Get("client", nil).(client.Client)
	k := client.NewKeysAPI(cli)

	if len(name) == 0 {
		return false, errors.New("Expected directory name to be more than zero characters.")
	}

	res, err := k.Set(dctx(), name, "", &client.SetOptions{TTL: ttl, Dir: true})
	if err != nil {
		return res, &cookoo.RecoverableError{err.Error()}
	}

	return res, nil
}
672790
func (g *Globber) filepaths(list []string, dir string, tree bool) (r []string) {
	var dirsep string
	if dir != "" {
		dirsep = dir + string(g.config.Separator)
		i := sort.SearchStrings(list, dirsep)
		if i >= len(list) {
			return
		}
		list = list[i:]
	}
	found := map[string]struct{}{}
	for _, path := range list {
		if dirsep != "" && !strings.HasPrefix(path, dirsep) {
			break
		}
		for j := len(dirsep); j < len(path); j++ {
			for j < len(path) && path[j] != g.config.Separator {
				j++
			}
			path := path[:j]
			if _, ok := found[path]; !ok {
				found[path] = struct{}{}
				r = append(r, path)
			}
			if !tree {
				break
			}
		}
	}
	return
}
701373
func GOPATH() []string {
	paths := strings.Split(os.Getenv("GOPATH"), string(os.PathListSeparator))
	if len(paths) == 0 {
		fmt.Println("GOPATH doesn't exist")
	}
	return paths
}
742378
func (repo *LocalRepository) Subpaths() []string {
	tails := make([]string, len(repo.PathParts))

	for i := range repo.PathParts {
		tails[i] = strings.Join(repo.PathParts[len(repo.PathParts)-(i+1):], "/")
	}

	return tails
}
550908
func MakePath(bucket, filename string) Path {
	var carr [2]string

	comps := carr[:0]
	if b := stripTrailingSlashes(bucket); b != "" {
		comps = append(comps, "gs://"+b)
	}
	if filename != "" {
		comps = append(comps, filename)
	}
	return Path(strings.Join(comps, "/"))
}
1361805
func GetGOPATHs() []string {
	gopath := os.Getenv("GOPATH")
	if gopath == "" && strings.Compare(runtime.Version(), "go1.8") >= 0 {
		gopath = defaultGOPATH()
	}
	return filepath.SplitList(gopath)
}
851144
func importPaths(args []string) []string {
	args = importPathsNoDotExpansion(args)
	var out []string
	for _, a := range args {
		if strings.Contains(a, "...") {
			if build.IsLocalImport(a) {
				out = append(out, allPackagesInFS(a)...)
			} else {
				out = append(out, allPackages(a)...)
			}
			continue
		}
		out = append(out, a)
	}
	return out
}