当前位置: 首页>>代码示例>>Golang>>正文


Golang Command.Usage方法代码示例

本文整理汇总了Golang中github.com/visualfc/gotools/command.Command.Usage方法的典型用法代码示例。如果您正苦于以下问题:Golang Command.Usage方法的具体用法?Golang Command.Usage怎么用?Golang Command.Usage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/visualfc/gotools/command.Command的用法示例。


在下文中一共展示了Command.Usage方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: runOracle

func runOracle(cmd *command.Command, args []string) error {
	if len(args) < 2 {
		cmd.Usage()
		return os.ErrInvalid
	}
	if os.Getenv("GOMAXPROCS") == "" {
		n := runtime.NumCPU()
		if n < 4 {
			n = 4
		}
		runtime.GOMAXPROCS(n)
	}
	mode := args[0]
	args = args[1:]
	if args[0] == "." {
		pkgPath, err := os.Getwd()
		if err != nil {
			log.Fatalln(err)
		}
		pkg, err := build.Default.ImportDir(pkgPath, 0)
		if err != nil {
			log.Fatalln(err)
		}
		args = pkg.GoFiles
		//log.Println(pkg.ImportPath)
		if pkg.ImportPath != "." && pkg.ImportPath != "" {
			args = []string{pkg.ImportPath}
		}
	}
	query := oracle.Query{
		Mode:       mode,
		Pos:        oraclePos,
		Build:      &build.Default,
		Scope:      args,
		PTALog:     nil,
		Reflection: oracleReflect,
	}

	if err := oracle.Run(&query); err != nil {
		fmt.Fprintf(os.Stderr, "oracle: %s.\n", err)
		return err
	}

	if mode == "referrers" {
		ref := query.Serial().Referrers
		if ref != nil {
			fmt.Fprintln(os.Stdout, ref.Desc)
			fmt.Fprintln(os.Stdout, ref.ObjPos)
			for _, v := range ref.Refs {
				fmt.Fprintln(os.Stdout, v)
			}
		}
	} else {
		query.WriteTo(os.Stdout)
	}
	return nil
}
开发者ID:ewindfall,项目名称:go-liteide-tools,代码行数:57,代码来源:oracle.go

示例2: runPkgs

func runPkgs(cmd *command.Command, args []string) error {
	runtime.GOMAXPROCS(runtime.NumCPU())
	if len(args) != 0 {
		cmd.Usage()
		return os.ErrInvalid
	}
	//pkgIndexOnce.Do(loadPkgsList)
	var pp PathPkgsIndex
	pp.LoadIndex()
	pp.Sort()
	if pkgsList {
		for _, pi := range pp.indexs {
			for _, pkg := range pi.pkgs {
				if pkgsPkgOnly && pkg.IsCommand() {
					continue
				}
				if pkgsJson {
					var p GoPackage
					p.copyBuild(pkg)
					b, err := json.MarshalIndent(&p, "", "\t")
					if err == nil {
						cmd.Stdout.Write(b)
						cmd.Stdout.Write([]byte{'\n'})
					}
				} else {
					cmd.Println(pkg.ImportPath)
				}
			}
		}
	} else if pkgsFind != "" {
		for _, pi := range pp.indexs {
			for _, pkg := range pi.pkgs {
				if pkg.Name == pkgsFind {
					if pkgsPkgOnly && pkg.IsCommand() {
						continue
					}
					if pkgsJson {
						var p GoPackage
						p.copyBuild(pkg)
						b, err := json.MarshalIndent(p, "", "\t")
						if err == nil {
							cmd.Stdout.Write(b)
							cmd.Stdout.Write([]byte{'\n'})
						}
					} else {
						cmd.Println(pkg.Name)
					}
					break
				}
			}
		}
	}
	return nil
}
开发者ID:ewindfall,项目名称:go-liteide-tools,代码行数:54,代码来源:pkgs.go

示例3: runCmd

func runCmd(cmd *command.Command, args []string) error {
	if len(args) == 0 {
		cmd.Usage()
		return os.ErrInvalid
	}
	if execWorkPath == "" {
		var err error
		execWorkPath, err = os.Getwd()
		if err != nil {
			fmt.Fprintf(os.Stderr, "liteide_stub exec: os.Getwd() false\n")
			command.SetExitStatus(3)
			command.Exit()
			return err
		}
	}
	fileName := args[0]

	filePath, err := exec.LookPath(fileName)
	if err != nil {
		filePath, err = exec.LookPath("./" + fileName)
	}
	if err != nil {
		fmt.Fprintf(os.Stderr, "liteide_stub exec: file %s not found\n", fileName)
		command.SetExitStatus(3)
		command.Exit()
	}

	fmt.Println("Starting Process", filePath, strings.Join(args[1:], " "), "...")

	command := exec.Command(filePath, args[1:]...)
	command.Dir = execWorkPath
	command.Stdin = os.Stdin
	command.Stdout = os.Stdout
	command.Stderr = os.Stderr

	err = command.Run()

	if err != nil {
		fmt.Println("\nEnd Process", err)
	} else {
		fmt.Println("\nEnd Process", "exit status 0")
	}

	exitWaitEnter()
	return nil
}
开发者ID:ewindfall,项目名称:go-liteide-tools,代码行数:46,代码来源:runcmd.go

示例4: runDoc

func runDoc(cmd *command.Command, args []string) error {
	if !(constantFlag || functionFlag || interfaceFlag || methodFlag || packageFlag || structFlag || typeFlag || variableFlag) { // none set
		constantFlag = true
		functionFlag = true
		methodFlag = true
		// Not package! It's special.
		typeFlag = true
		variableFlag = true
	}
	if !(docFlag || srcFlag || urlFlag) {
		docFlag = true
		srcFlag = true
		urlFlag = true
	}
	var pkg, name string
	switch len(args) {
	case 1:
		if packageFlag {
			pkg = args[0]
		} else if regexpFlag {
			name = args[0]
		} else if strings.Contains(args[0], ".") {
			pkg, name = split(args[0])
		} else {
			name = args[0]
		}
	case 2:
		if packageFlag {
			cmd.Usage()
		}
		pkg, name = args[0], args[1]
	default:
		cmd.Usage()
		return os.ErrInvalid
	}
	if strings.Contains(pkg, "/") {
		fmt.Fprintf(os.Stderr, "doc: package name cannot contain slash (TODO)\n")
		os.Exit(2)
	}
	for _, path := range Paths(pkg) {
		lookInDirectory(path, name)
	}
	return nil
}
开发者ID:ewindfall,项目名称:go-liteide-tools,代码行数:44,代码来源:finddoc.go

示例5: runPresent

func runPresent(cmd *command.Command, args []string) error {
	if presentInput == "" || !isDoc(presentInput) {
		cmd.Usage()
		return os.ErrInvalid
	}

	if presentVerifyOnly {
		err := VerifyDoc(presentInput)
		if err != nil {
			fmt.Fprintf(os.Stderr, "present:%s", err)
			command.SetExitStatus(3)
			command.Exit()
		}
		return nil
	}
	w := os.Stdout
	if !presentStdout {
		if presentOutput == "" {
			presentOutput = presentInput + ".html"
		}
		ext := filepath.Ext(presentOutput)
		if ext != ".htm" && ext != ".html" {
			presentOutput += ".html"
		}
		var err error
		w, err = os.Create(presentOutput)
		if err != nil {
			fmt.Fprintf(os.Stderr, "present:%s", err)
			command.SetExitStatus(3)
			command.Exit()
		}
	}
	err := RenderDoc(w, presentInput)
	if err != nil {
		fmt.Fprintf(os.Stderr, "present:%s", err)
		command.SetExitStatus(3)
		command.Exit()
	}
	return nil
}
开发者ID:ewindfall,项目名称:go-liteide-tools,代码行数:40,代码来源:gopresent.go

示例6: runAstView

func runAstView(cmd *command.Command, args []string) error {
	if len(args) == 0 {
		cmd.Usage()
		return os.ErrInvalid
	}
	if astViewStdin {
		view, err := NewFilePackageSource(args[0], os.Stdin, true)
		if err != nil {
			fmt.Fprintf(os.Stderr, "astview: %s", err)
			command.SetExitStatus(3)
			command.Exit()
		}
		view.PrintTree(os.Stdout)
	} else {
		err := PrintFilesTree(args, os.Stdout, true)
		if err != nil {
			fmt.Fprintf(os.Stderr, "astview:%s", err)
			command.SetExitStatus(3)
			command.Exit()
		}
	}
	return nil
}
开发者ID:ewindfall,项目名称:go-liteide-tools,代码行数:23,代码来源:astview.go

示例7: runDocView

func runDocView(cmd *command.Command, args []string) error {
	if docViewFind == "" && docViewList == "" {
		cmd.Usage()
		return os.ErrInvalid
	}

	var template string
	var info *Info
	if len(docViewList) > 0 {
		pkgPath := filepath.Join(goroot, "src", docViewList)
		if docViewList == "pkg" {
			_, err := os.Stat(pkgPath)
			if err != nil {
				pkgPath = filepath.Join(goroot, "src")
			}
		}
		info = NewListInfo(pkgPath)
		if info != nil {
			if docViewList == "pkg" {
				var filterList []DirEntry
				for _, v := range info.Dirs.List {
					if v.Path == "cmd" {
						continue
					}
					if strings.HasPrefix(v.Path, "cmd/") {
						continue
					}
					if strings.Contains(v.Path, "/testdata") {
						continue
					}
					filterList = append(filterList, v)
				}
				info.Dirs.List = filterList
			} else if docViewList == "cmd" {
				var filterList []DirEntry
				for _, v := range info.Dirs.List {
					if strings.Contains(v.Path, "/") {
						continue
					}
					if strings.Contains(v.Path, "internal") {
						continue
					}
					filterList = append(filterList, v)
				}
				info.Dirs.List = filterList
			}
		}
		switch docViewMode {
		case "html":
			template = listHTML
		case "lite":
			template = listLite
		case "text":
			template = listText
		default:
			template = listText
		}
	} else if len(docViewFind) > 0 {
		dir := NewSourceDir(goroot)
		info = dir.FindInfo(docViewFind)
		switch docViewMode {
		case "html":
			template = findHTML
		case "lite":
			template = findLite
		case "text":
			template = findText
		default:
			template = findText
		}
	}
	if info == nil {
		fmt.Fprintf(os.Stderr, "<error>\n")
		command.SetExitStatus(3)
		command.Exit()
	}
	contents := info.GetPkgList(docViewMode, template)
	fmt.Fprintf(os.Stdout, "%s", contents)
	return nil
}
开发者ID:ewindfall,项目名称:go-liteide-tools,代码行数:80,代码来源:docview.go

示例8: runTypes

func runTypes(cmd *command.Command, args []string) error {
	if len(args) < 1 {
		cmd.Usage()
		return nil
	}
	if typesVerbose {
		now := time.Now()
		defer func() {
			log.Println("time", time.Now().Sub(now))
		}()
	}
	w := NewPkgWalker(&build.Default)

	var cursor *FileCursor
	if typesFilePos != "" {
		var cursorInfo FileCursor
		pos := strings.Index(typesFilePos, ":")
		if pos != -1 {
			cursorInfo.fileName = typesFilePos[:pos]
			if i, err := strconv.Atoi(typesFilePos[pos+1:]); err == nil {
				cursorInfo.cursorPos = i
			}
		}
		if typesFileStdin {
			src, err := ioutil.ReadAll(os.Stdin)
			if err == nil {
				cursorInfo.src = src
			}
		}
		cursor = &cursorInfo
	}

	for _, pkgName := range args {
		if pkgName == "." {
			pkgPath, err := os.Getwd()
			if err != nil {
				log.Fatalln(err)
			}
			pkgName = pkgPath
			w.CurrPackage = pkgName
		}

		conf := &PkgConfig{IgnoreFuncBodies: true, AllowBinary: true, WithTestFiles: true}
		if cursor != nil {
			conf.Cursor = cursor
			conf.IgnoreFuncBodies = false
			conf.Info = &types.Info{
				Uses:       make(map[*ast.Ident]types.Object),
				Defs:       make(map[*ast.Ident]types.Object),
				Selections: make(map[*ast.SelectorExpr]*types.Selection),
				//Types:      make(map[ast.Expr]types.TypeAndValue),
				//Scopes: make(map[ast.Node]*types.Scope),
				//Implicits : make(map[ast.Node]types.Object)
			}
			conf.XInfo = &types.Info{
				Uses:       make(map[*ast.Ident]types.Object),
				Defs:       make(map[*ast.Ident]types.Object),
				Selections: make(map[*ast.SelectorExpr]*types.Selection),
			}
		}

		pkg, err := w.Import("", pkgName, conf)

		if pkg == nil {
			log.Fatalln("error import path", err)
		}

		if cursor != nil && (typesFindInfo || typesFindDef || typesFindUse) {
			w.LookupCursor(pkg, conf, cursor)
		}
	}
	return nil
}
开发者ID:donseba,项目名称:gotools,代码行数:73,代码来源:types.go


注:本文中的github.com/visualfc/gotools/command.Command.Usage方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。