// Check should be invoked in the init function.
// It will check your package dependencies, if the dependencies is inconsistent
// with Pakfile.lock, it force the program to exit. However, Check allows
// packages to be dirty or not on pak branch as long as the package is marked
// managed, that is to say, you has run pak get before calling Check.
// TODO: add tests
Check should be invoked in the init function.
It will check your package dependencies, if the dependencies is inconsistent
with Pakfile.lock, it force the program to exit. However, Check allows
packages to be dirty or not on pak branch as long as the package is marked
managed, that is to say, you has run pak get before calling Check.
TODO: add tests
// Check should be invoked in the init function . // It will check your package dependencies if the dependencies is inconsistent // with Pakfile . lock it force the program to exit . However Check allows // packages to be dirty or not on pak branch as long as the package is marked // managed that is to say you has run pak get before calling Check . // TODO : add tests
func Check() {
	allPakPkgs, err := ParsePakfile()
	if err != nil {
		color.Printf("Force Exited by Pak: @r%s@w.\n", err.Error())
		os.Exit(1)
	}
	paklockInfo, err := GetPaklockInfo("")
	if err != nil {
		color.Printf("Force Exited by Pak: @r%s@w. Please run @bpak get@w.\n", err.Error())
		os.Exit(1)
	}
	errors := [][2]string{}
	warnings := [][2]string{}
	for _, pakPkg := range allPakPkgs {
		err := pakPkg.Dial()
		if err != nil {
			color.Printf("Force Exited by Pak: @r%s@w.\n", err.Error())
			os.Exit(1)
		}
		err = pakPkg.Sync()
		if err != nil {
			color.Printf("Force Exited by Pak: @r%s@w. Please run @bpak get@w.\n", err.Error())
			os.Exit(1)
		}
		checksum := paklockInfo[pakPkg.Name]
		if checksum == "" {
			errors = append(errors, [2]string{pakPkg.Name, "New Package, Not Yet Managed by Pak."})
			continue
		}
		if !pakPkg.OnPakbranch {
			warnings = append(warnings, [2]string{pakPkg.Name, "Not on Pak Branch."})
			continue
		}
		if !pakPkg.IsClean {
			warnings = append(warnings, [2]string{pakPkg.Name, "Is Not Clean."})
			continue
		}
		if pakPkg.PakbranchChecksum != checksum {
			errors = append(errors, [2]string{pakPkg.Name, "Inconsistent with Pakfile.lock."})
			continue
		}
	}
	if len(warnings) > 0 {
		paddingLen := 0
		for _, info := range errors {
			if len(info[0]) > paddingLen {
				paddingLen = len(info[0])
			}
		}
		color.Println("Warning: Packages below are out of the control of Pak:")
		paddingStr := fmt.Sprintf(`@g%%-%d`, paddingLen)
		for _, warning := range warnings {
			color.Printf(paddingStr+`s @w-> @r%s`, warning[0], warning[1])
			fmt.Println()
		}
	}
	if len(errors) == 0 {
		return
	}
	paddingLen := 0
	for _, info := range errors {
		if len(info[0]) > paddingLen {
			paddingLen = len(info[0])
		}
	}
	color.Println("Force Exited by Pak. Packages listed below is not under the control of Pak:")
	paddingStr := fmt.Sprintf(`@g%%-%d`, paddingLen)
	for _, info := range errors {
		color.Printf(paddingStr+`s @w-> @r%s`, info[0], info[1])
		fmt.Println()
	}
	color.Print("Please run @bpak get@w before restarting your program.\n")
	os.Exit(1)
}
func Check ( ) { allPakPkgs , err := ParsePakfile ( ) if err != nil { color . Printf ( " \n " , err . Error ( ) ) os . Exit ( 1 ) } paklockInfo , err := GetPaklockInfo ( " " ) if err != nil { color . Printf ( " \n " , err . Error ( ) ) os . Exit ( 1 ) } errors := [ ] [ 2 ] string { } warnings := [ ] [ 2 ] string { } for _ , pakPkg := range allPakPkgs { err := pakPkg . Dial ( ) if err != nil { color . Printf ( " \n " , err . Error ( ) ) os . Exit ( 1 ) } err = pakPkg . Sync ( ) if err != nil { color . Printf ( " \n " , err . Error ( ) ) os . Exit ( 1 ) } checksum := paklockInfo [ pakPkg . Name ] if checksum == " " { errors = append ( errors , [ 2 ] string { pakPkg . Name , " " } ) continue } if ! pakPkg . OnPakbranch { warnings = append ( warnings , [ 2 ] string { pakPkg . Name , " " } ) continue } if ! pakPkg . IsClean { warnings = append ( warnings , [ 2 ] string { pakPkg . Name , " " } ) continue } if pakPkg . PakbranchChecksum != checksum { errors = append ( errors , [ 2 ] string { pakPkg . Name , " " } ) continue } } if len ( warnings ) > 0 { paddingLen := 0 for _ , info := range errors { if len ( info [ 0 ] ) > paddingLen { paddingLen = len ( info [ 0 ] ) } } color . Println ( " " ) paddingStr := fmt . Sprintf ( `@g%%-%d` , paddingLen ) for _ , warning := range warnings { color . Printf ( paddingStr + `s @w-> @r%s` , warning [ 0 ] , warning [ 1 ] ) fmt . Println ( ) } } if len ( errors ) == 0 { return } paddingLen := 0 for _ , info := range errors { if len ( info [ 0 ] ) > paddingLen { paddingLen = len ( info [ 0 ] ) } } color . Println ( " " ) paddingStr := fmt . Sprintf ( `@g%%-%d` , paddingLen ) for _ , info := range errors { color . Printf ( paddingStr + `s @w-> @r%s` , info [ 0 ] , info [ 1 ] ) fmt . Println ( ) } color . Print ( " \n " ) os . Exit ( 1 ) }
Check should be invoked in the init function.
Check should be invoked in the init function .
// Parse