INNER CODE UNIT · Go

writeAppend

sunny0826/kubecm · cmd/alias.go:97

func writeAppend(context, path string) error {
	f, err := os.OpenFile(path, os.O_RDWR|os.O_APPEND, 0666)
	if err != nil {
		return err
	}
	defer f.Close()
	var exist bool
	scanner := bufio.NewScanner(f)
	for scanner.Scan() {
		line := scanner.Text()
		if ok := strings.EqualFold(SourceCmd, line); ok {
			exist = true
			break
		}
	}
	if !exist {
		write := bufio.NewWriter(f)
		_, _ = write.WriteString(context + "\n")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…