Exemple #1
0
func demo() {
	lines, _ := mcore.ReadFileLines(location)

	v, err := mcore.GetConfigValue(lines, "username", ":")
	fmt.Printf("%s:%v\n", v, err)

	v2, err2 := mcore.GetConfigValue(lines, "password", ":")
	fmt.Printf("%s:%v\n", v2, err2)

	v3, err3 := mcore.GetConfigValue(lines, "none", ":")
	fmt.Printf("%s:%v\n", v3, err3)
}
Exemple #2
0
func show(item string) {
	//found
	data, err := mcore.ReadFileLines(item)
	if err != nil {
		fmt.Println(err)
		return
	}
	for lineNum, line := range data {
		if strings.Contains(line, searchStr) {
			fmt.Printf("%d %s\n", lineNum, line)
		}
	}
}
Exemple #3
0
func Search(path string, exts string, recursive bool, skipDirs, skipFiles, content string) {
	files := mcore.GetSubFiles(path, recursive, exts, skipDirs, skipFiles)
	for _, item := range files {
		text, err := mcore.ReadFileAll(item)
		if nil != err {
			continue
		}

		if !strings.Contains(text, content) {
			if verbose {
				fmt.Printf("File: %s not found matches\n", item)
			}
			continue
		} else {
			nums := strings.Count(text, content)
			fmt.Printf("File: %s found %d matches.\n", item, nums)
		}

		//found
		data, err := mcore.ReadFileLines(item)

		if err != nil {
			fmt.Println(err)
			continue
		}

		for lineNum, line := range data {
			if strings.Contains(line, content) {
				fmt.Printf("%d ", lineNum+1)
				lineA := mcore.String(line).Split(content)
				for i, v := range lineA {
					fmt.Printf(v)
					if i != len(lineA)-1 {
						mcon.PrintGreen(content)
					}
				}
				fmt.Println()
			}
		}
	}
}