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


Golang someutils.Invocation类代码示例

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


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


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