• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang someutils.Invocation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/laher/someutils.Invocation的典型用法代码示例。如果您正苦于以下问题:Golang Invocation类的具体用法?Golang Invocation怎么用?Golang Invocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



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

示例1: Invoke

// Exec actually performs the head
func (head *SomeHead) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	//TODO do something here!
	if len(head.Filenames) > 0 {
		for _, fileName := range head.Filenames {
			file, err := os.Open(fileName)
			if err != nil {
				return err, 1
			}
			//err = headFile(file, head, invocation.MainPipe.Out)
			err = head.head(invocation.MainPipe.Out, file)
			if err != nil {
				file.Close()
				return err, 1
			}
			err = file.Close()
			if err != nil {
				return err, 1
			}
		}
	} else {
		//stdin ..
		err := head.head(invocation.MainPipe.Out, invocation.MainPipe.In)
		if err != nil {
			return err, 1
		}
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:31,代码来源:head.go


示例2: Invoke

// Exec actually performs the tee
func (tee *SomeTee) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	flag := os.O_CREATE
	if tee.isAppend {
		flag = flag | os.O_APPEND
	}
	writeables := uggo.ToWriteableOpeners(tee.args, flag, 0666)
	files, err := uggo.OpenAll(writeables)
	if err != nil {
		return err, 1
	}
	writers := []io.Writer{invocation.MainPipe.Out}
	for _, file := range files {
		writers = append(writers, file)
	}
	multiwriter := io.MultiWriter(writers...)
	_, err = io.Copy(multiwriter, invocation.MainPipe.In)
	if err != nil {
		return err, 1
	}
	for _, file := range files {
		err = file.Close()
		if err != nil {
			return err, 1
		}
	}
	return nil, 0

}
开发者ID:ando-masaki,项目名称:someutils,代码行数:31,代码来源:tee.go


示例3: Invoke

// Exec actually performs the dirname
func (dirname *SomeDirname) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	for _, f := range dirname.Filenames {
		dir := path.Dir(f)
		fmt.Fprintln(invocation.MainPipe.Out, dir)
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:10,代码来源:dirname.go


示例4: Invoke

// Exec actually performs the pwd
func (pwd *SomePwd) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	wd, err := os.Getwd()
	if err != nil {
		return err, 1
	}
	fmt.Fprintln(invocation.MainPipe.Out, wd)
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:11,代码来源:pwd.go


示例5: Invoke

// Exec actually performs the zip
func (z *SomeZip) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	err := ZipItems(z.zipFilename, z.items)
	if err != nil {
		return err, 1
	}
	return nil, 0

}
开发者ID:ando-masaki,项目名称:someutils,代码行数:11,代码来源:zip.go


示例6: Invoke

// Exec actually performs the touch
func (touch *SomeTouch) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	for _, filename := range touch.args {
		err := touchFile(filename)
		if err != nil {
			return err, 1
		}
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:12,代码来源:touch.go


示例7: Invoke

func (cat *SomeCat) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	if len(cat.FileNames) > 0 {
		for _, fileName := range cat.FileNames {
			file, err := os.Open(fileName)
			if err != nil {
				return err, 1
			} else {
				if cat.isStraightCopy() {
					_, err = io.Copy(invocation.MainPipe.Out, file)
					if err != nil {
						return err, 1
					}
				} else {
					scanner := bufio.NewScanner(file)
					line := 1
					var prefix string
					var suffix string
					for scanner.Scan() {
						text := scanner.Text()
						if !cat.IsSqueezeBlank || len(strings.TrimSpace(text)) > 0 {
							if cat.IsNumber {
								prefix = fmt.Sprintf("%d ", line)
							} else {
								prefix = ""
							}
							if cat.IsShowEnds {
								suffix = "$"
							} else {
								suffix = ""
							}
							fmt.Fprintf(invocation.MainPipe.Out, "%s%s%s\n", prefix, text, suffix)
						}
						line++
					}
					err := scanner.Err()
					if err != nil {
						return err, 1
					}
				}
				file.Close()
			}
		}
	} else {
		_, err := io.Copy(invocation.MainPipe.Out, invocation.MainPipe.In)
		if err != nil {
			return err, 1
		}
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:52,代码来源:cat.go


示例8: Invoke

// Exec actually performs the which
func (which *SomeWhich) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	path := os.Getenv("PATH")
	if runtime.GOOS == "windows" {
		path = ".;" + path
	}
	pl := filepath.SplitList(path)
	for _, arg := range which.args {
		checkPathParts(arg, pl, which, invocation.MainPipe.Out)
	}
	return nil, 0

}
开发者ID:ando-masaki,项目名称:someutils,代码行数:15,代码来源:which.go


示例9: Invoke

// Invoke actually carries out the command
func (tr *SomeTr) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	tr.Preprocess()
	fu := func(inPipe io.Reader, outPipe2 io.Writer, errPipe io.Writer, line []byte) error {
		//println("tr processing line")
		//outline := line
		var buffer bytes.Buffer
		remainder := string(line)
		for len(remainder) > 0 {
			trimLeft := 1
			nextPart := remainder[:trimLeft]
			for reg, v := range tr.translations {
				//fmt.Printf("Translation '%v'=>'%s' on '%s'\n", reg, v, remainder)
				match := reg.MatchString(remainder)
				if match {
					toReplace := reg.FindString(remainder)
					replacement := reg.ReplaceAllString(toReplace, v)
					//fmt.Printf("Replace %s=>%s\n", toReplace, replacement)
					nextPart = replacement
					//if squeezing has taken place, remove more leading chars accordingly
					trimLeft = len(toReplace)
					if !tr.IsComplement {
						break
					}
				} else if tr.IsComplement {
					// this is a double-negative - non-match of negative-regex.
					// This implies that set1 matches the current input character.
					// So, keep it as-is and break out of the loop.
					trimLeft = 1
					nextPart = remainder[:trimLeft]
					break
				}
			}

			remainder = remainder[trimLeft:]
			buffer.WriteString(nextPart)
		}
		out := buffer.String()
		_, err := fmt.Fprintln(outPipe2, out)
		return err
	}
	err := someutils.LineProcessor(invocation.MainPipe.In, invocation.MainPipe.Out, invocation.ErrPipe.Out, fu)
	if err != nil {
		return err, 1
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:49,代码来源:tr.go


示例10: Invoke

// Exec actually performs the unzip
func (unzip *SomeUnzip) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	if unzip.isTest {
		err := TestItems(unzip.zipname, unzip.files, invocation.MainPipe.Out, invocation.ErrPipe.Out)
		if err != nil {
			return err, 1
		}
	} else {
		err := UnzipItems(unzip.zipname, unzip.destDir, unzip.files, invocation.ErrPipe.Out)
		if err != nil {
			return err, 1
		}
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:17,代码来源:unzip.go


示例11: Invoke

// Exec actually performs the xargs
func (xargs *SomeXargs) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	util := xargs.utilFactory()
	args := xargs.newArgset(util.Name())
	reader := bufio.NewReader(invocation.MainPipe.In)
	cont := true
	count := 0
	maxCount := 5
	for cont {
		if count >= maxCount {
			count = 0
			//fmt.Fprintf(errPipe, "args for '%s': %v\n", util.Name(), args)
			err, code := util.ParseFlags(args, invocation.ErrPipe.Out)
			if err != nil {
				return err, code
			}
			err, code = util.Invoke(invocation)
			if err != nil {
				return err, code
			}
		}
		line, _, err := reader.ReadLine()
		if err == io.EOF {
			cont = false
		} else if err != nil {
			return err, 1
		} else {
			args = append(args, string(line))
			if err != nil {
				return err, 1
			}
			count++
		}
	}
	//still more args to process
	if count > 0 {
		//fmt.Fprintf(errPipe, "args for '%s': %v\n", util.Name(), args)
		err, code := util.ParseFlags(args, invocation.ErrPipe.Out)
		if err != nil {
			return err, code
		}
		err, code = util.Invoke(invocation)
		return err, code
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:48,代码来源:xargs.go


示例12: Invoke

// Exec actually performs the gunzip
func (gunzip *SomeGunzip) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	if gunzip.IsTest {
		err := TestGzipItems(gunzip.Filenames)
		if err != nil {
			return err, 1
		}
	} else {
		err := gunzip.gunzipItems(invocation.MainPipe.In, invocation.MainPipe.Out, invocation.ErrPipe.Out)
		if err != nil {
			return err, 1
		}
	}
	return nil, 0

}
开发者ID:ando-masaki,项目名称:someutils,代码行数:18,代码来源:gunzip.go


示例13: Invoke

// Exec actually performs the cp
func (cp *SomeCp) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	for _, srcGlob := range cp.SrcGlobs {
		srces, err := filepath.Glob(srcGlob)
		if err != nil {
			return err, 1
		}
		for _, src := range srces {
			err = copyFile(src, cp.Dest, cp)
			if err != nil {
				return err, 1
			}
		}
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:18,代码来源:cp.go


示例14: Invoke

// Exec actually performs the rm
func (rm *SomeRm) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	for _, fileGlob := range rm.fileGlobs {
		files, err := filepath.Glob(fileGlob)
		if err != nil {
			return err, 1
		}
		for _, file := range files {
			err := delete(file, rm.IsRecursive)
			if err != nil {
				return err, 1
			}
		}
	}

	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:19,代码来源:rm.go


示例15: Invoke

// Exec actually performs the basename
func (basename *SomeBasename) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	if basename.RelativeTo != "" {
		last := strings.LastIndex(basename.RelativeTo, basename.InputPath)
		base := basename.InputPath[:last]
		_, err := fmt.Fprintln(invocation.MainPipe.Out, base)
		if err != nil {
			return err, 1
		}
	} else {
		_, err := fmt.Fprintln(invocation.MainPipe.Out, path.Base(basename.InputPath))
		if err != nil {
			return err, 1
		}
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:19,代码来源:basename.go


示例16: Invoke

// Exec actually performs the sleep
func (sleep *SomeSleep) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	var unitDur time.Duration
	switch sleep.unit {
	case "d":
		unitDur = time.Hour * 24
	case "s":
		unitDur = time.Second
	case "m":
		unitDur = time.Minute
	case "h":
		unitDur = time.Hour
	default:
		return errors.New("Invalid time interval " + sleep.unit), 1
	}
	time.Sleep(time.Duration(sleep.amount) * unitDur)
	return nil, 0

}
开发者ID:ando-masaki,项目名称:someutils,代码行数:21,代码来源:sleep.go


示例17: Invoke

// Exec actually performs the tar
func (t *SomeTar) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	//overrideable??
	destDir := "."
	if t.IsCreate {
		//OK
		//fmt.Printf("Create %s\n", t.ArchiveFilename)
		err := TarItems(t.ArchiveFilename, t.args, t, invocation.MainPipe.Out)
		if err != nil {
			return err, 1
		}
	} else if t.IsAppend {
		//hmm is this OK with STDIN??
		if t.ArchiveFilename == "" {
			return errors.New("Filename (-f) must be provided in Append mode"), 1
		}
		//OK
		//fmt.Printf("Append %s\n", t.ArchiveFilename)
		err := TarItems(t.ArchiveFilename, t.args, t, invocation.MainPipe.Out)
		if err != nil {
			return err, 1
		}
	} else if t.IsList {
		//fmt.Println("List", t.ArchiveFilename)
		err := TestTarItems(t.ArchiveFilename, t.args, invocation.MainPipe.In, invocation.MainPipe.Out)
		if err != nil {
			return err, 1
		}
	} else if t.IsExtract {
		//fmt.Println("Extract", t.ArchiveFilename)
		err := UntarItems(t.ArchiveFilename, destDir, t.args, t, invocation.MainPipe.In, invocation.MainPipe.Out)
		if err != nil {
			return err, 1
		}
	} else {
		return errors.New("You must use ONLY one of -c, -t or -x (create, list or extract), plus -f"), 1
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:41,代码来源:tar.go


示例18: Invoke

// Exec actually performs the exec
func (exe *SomeExec) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	cmd := exec.Command(exe.args[0], exe.args[1:]...)
	cmd.Stdin = invocation.MainPipe.In
	cmd.Stdout = invocation.MainPipe.Out
	cmd.Stderr = invocation.ErrPipe.Out
	err := cmd.Start()
	if err != nil {
		return err, 1
	}
	err = cmd.Wait()
	exitSuccess := cmd.ProcessState.Success()
	var exitCode int
	if exitSuccess {
		exitCode = 0
	} else {
		// There should be a way to get the proper status on Unix.
		exitCode = 1
	}
	return err, exitCode
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:23,代码来源:exec.go


示例19: Invoke

// Exec actually performs the mv
func (mv *SomeMv) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	for _, srcGlob := range mv.srcGlobs {
		srces, err := filepath.Glob(srcGlob)
		if err != nil {
			return err, 1
		}
		if len(srces) < 1 {
			return errors.New(fmt.Sprintf("Source glob '%s' does not match any files\n", srcGlob)), 1
		}

		for _, src := range srces {
			err = moveFile(src, mv.dest)
			if err != nil {
				fmt.Fprintf(invocation.ErrPipe.Out, "Error %v\n", err)
				return err, 1
			}
		}
	}
	return nil, 0

}
开发者ID:ando-masaki,项目名称:someutils,代码行数:24,代码来源:mv.go


示例20: Invoke

// Exec actually performs the grep
func (grep *SomeGrep) Invoke(invocation *someutils.Invocation) (error, int) {
	invocation.ErrPipe.Drain()
	invocation.AutoHandleSignals()
	reg, err := compile(grep.pattern, grep)
	if err != nil {
		return err, 1
	}
	if len(grep.globs) > 0 {
		files := []string{}
		for _, glob := range grep.globs {
			results, err := filepath.Glob(glob)
			if err != nil {
				return err, 1
			}
			if len(results) < 1 { //no match
				return errors.New("grep: cannot access " + glob + ": No such file or directory"), 1
			}
			files = append(files, results...)
		}
		err = grepAll(reg, files, grep, invocation.MainPipe.Out)
		if err != nil {
			return err, 1
		}
	} else {
		if uggo.IsPipingStdin() {
			//check STDIN
			err = grepReader(invocation.MainPipe.In, "", reg, grep, invocation.MainPipe.Out)
			if err != nil {
				return err, 1
			}
		} else {
			//NOT piping.
			return errors.New("Not enough args"), 1
		}
	}
	return nil, 0
}
开发者ID:ando-masaki,项目名称:someutils,代码行数:38,代码来源:grep.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang uggo.NewFlagSetDefault函数代码示例发布时间:2022-05-23
下一篇:
Golang config.Settings类代码示例发布时间:2022-05-23
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap