當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。