// ImportPakCheck will scan the whole package and try to find out what kind of packages that is needed to be managed by pak, then save the result in Pakfile.
// TODO: auto detect packages and setting up a complete and basic Pakfile
ImportPakCheck will scan the whole package and try to find out what kind of packages that is needed to be managed by pak, then save the result in Pakfile.
TODO: auto detect packages and setting up a complete and basic Pakfile
// ImportPakCheck will scan the whole package and try to find out what kind of packages that is needed to be managed by pak then save the result in Pakfile . // TODO : auto detect packages and setting up a complete and basic Pakfile
func ImportPakCheck() (err error) {
	 if gofileCount > 1 {
	 	 create a file to auto-check package dependences
	 	err = ioutil.WriteFile("pak.go", []byte(fmt.Sprintf(checkTemplate), pkgName), os.FileMode(0644))
	 else if gofileCount == 1 && mainGoFile != "" {
	 	 modify the only go file to auto-check package dependences
	 	f, err := os.Open(mainGoFile)
	 	if err != nil {
	 	    return err
	 	}
	 	reader := bufio.NewReader(f)
	 	lineBytes, _, err := reader.ReadLine()
	 	if err != nil {
	 	    return err
	 	}
	 	fileContent := ""
	 	importContent := "import (\n"
	 	singleLineImportExp := regexp.MustCompile(`^import ("[^"]+")$`)
	 	multipleLinesImportStartExp := regexp.MustCompile(`^import ?\( ?$`)
	 	multipleLinesImportEndExp := regexp.MustCompile(`^ ?) ?$`)
	 	inImportBlock := false
	 	for reader.Buffered() != 0 {
	 		line := string(lineBytes)
	 		switch{
	 		case singleLineImportExp.MatchString(line):
	 			pkg := singleLineImportExp.FindStringSubmatch(line)
	 			if len(pkg) != 2 {
	 				return fmt.Errorf("Can't Detect Package Name.")
	 			}
	 			line = fmt.Sprintf("import (\n    \"github.com/theplant/pak/check\",\n    %s\n)\n", pkg[1])
	 			line += "\nfunc init() {\ncheck.Check()\n}\n"
	 		case multipleLinesImportStartExp.MatchString(line):
	 			inImportBlock = true
	 		case inImportBlock && multipleLinesImportEndExp.MatchString(line):
	 			inImportBlock = false
	 		case inImportBlock:
	 		default:
	 		}
	 		if inImportBlock {
	 			importContent += line
	 		} else {
	 			fileContent += line
	 		}
	 		 pkg := packageExp.FindStringSubmatch(string(line))
	 		if len(pkg) == 2 {
	 			pkgName = pkg[1]
	 			return nil
	 		}
	 		lineBytes, _, err = reader.ReadLine()
	 		if err != nil {
	 		    return err
	 		}
	 	}
	return err
}
func ImportPakCheck ( ) ( err error ) { return err }
ImportPakCheck will scan the whole package and try to find out what kind of packages that is needed to be managed by pak, then save the result in Pakfile.
ImportPakCheck will scan the whole package and try to find out what kind of packages that is needed to be managed by pak then save the result in Pakfile .
// pkgName, gofileCount, mainGoFile, err := parsePkg() // if err != nil { //     return err // } // // if gofileCount > 1 { // 	// create a file to auto-check package dependences // // 	err = ioutil.WriteFile("pak.go", []byte(fmt.Sprintf(checkTemplate), pkgName), os.FileMode(0644)) // } else if gofileCount == 1 && mainGoFile != "" { // 	// modify the only go file to auto-check package dependences // // 	f, err := os.Open(mainGoFile) // 	if err != nil { // 	    return err // 	} // // 	reader := bufio.NewReader(f) // 	lineBytes, _, err := reader.ReadLine() // 	if err != nil { // 	    return err // 	} // // 	fileContent := "" // 	importContent := "import (\n" // 	singleLineImportExp := regexp.MustCompile(`^import ("[^"]+")$`) // 	multipleLinesImportStartExp := regexp.MustCompile(`^import ?\( ?$`) // 	multipleLinesImportEndExp := regexp.MustCompile(`^ ?) ?$`) // 	inImportBlock := false // // 	for reader.Buffered() != 0 { // 		line := string(lineBytes) // // 		switch{ // 		case singleLineImportExp.MatchString(line): // 			pkg := singleLineImportExp.FindStringSubmatch(line) // 			if len(pkg) != 2 { // 				return fmt.Errorf("Can't Detect Package Name.") // 			} // // 			line = fmt.Sprintf("import (\n    \"github.com/theplant/pak/check\",\n    %s\n)\n", pkg[1]) // 			line += "\nfunc init() {\ncheck.Check()\n}\n" // 		case multipleLinesImportStartExp.MatchString(line): // 			inImportBlock = true // // 		case inImportBlock && multipleLinesImportEndExp.MatchString(line): // 			inImportBlock = false // 		case inImportBlock: // // 		default: // // 		} // // 		if inImportBlock { // 			importContent += line // 		} else { // 			fileContent += line // 		} // // 		// pkg := packageExp.FindStringSubmatch(string(line)) // // 		if len(pkg) == 2 { // 			pkgName = pkg[1] // 			return nil // 		} // // 		lineBytes, _, err = reader.ReadLine() // 		if err != nil { // 		    return err // 		} // 	} // } //