Ejemplo n.º 1
0
func main() {
	// Read preferences
	gubase.ReadPrefs()
	fmt.Println("")

	// Show notice
	notice()

	// Validate argument count
	if len(os.Args) < 3 {
		usage()
		os.Exit(1)
	}

	// Find and call command
	command, action := os.Args[1], os.Args[2]
	target, ok := Registry[command]
	if ok {
		fmt.Fprintln(os.Stderr, gubase.Color(target.Title, gubase.ColorWhite))
		fmt.Println("")
		target.Do(action, os.Args[3:])
	} else {
		fmt.Fprintln(
			os.Stderr,
			gubase.Color("Command not found", gubase.ColorRed))
		os.Exit(1)
	}

	// Write preferences
	fmt.Println("")
	gubase.WritePrefs()
}
Ejemplo n.º 2
0
func DoSearch(args []string) {
	// Get params
	var flagSet = flag.NewFlagSet("search", flag.ExitOnError)

	var marketName string
	flagSet.StringVar(&marketName, "m", "", fmt.Sprintln(DefaultMarkets))

	flagSet.Parse(args)

	var market int
	if len(marketName) > 0 {
		market = DefaultMarkets[marketName]
	}

	// Make request
	result := Request(&SearchUtility{market}).(SearchResult)

	// Show results
	for _, item := range result.Items {
		// Description
		fmt.Printf(
			gubase.Color("● %s » %s\n", gubase.ColorWhite),
			item.SeekArea, item.Address)
		fmt.Printf(
			"%s, %s m², floor %s\n",
			item.Description, item.Area, item.Floor)

		// Rent
		fmt.Printf(gubase.Color("%.0f SEK\n", gubase.ColorGreen), item.Rent)

		// Properties
		for _, property := range item.Properties {
			fmt.Printf("  ● %s\n", property.Description)
		}

		// Dates
		fmt.Printf("        Apply before: %s\n", item.LastDay)
		fmt.Printf("           Free from: %s\n", item.FreeFrom)

		fmt.Println("")
	}

	fmt.Printf(
		gubase.Color("%d results\n", gubase.ColorWhite),
		result.TotalCount)
}
Ejemplo n.º 3
0
func notice() {
	fmt.Fprintln(os.Stderr, gubase.Color("** GU-CLI **", gubase.ColorWhite))
	fmt.Fprintln(os.Stderr, "")

	fmt.Fprintln(
		os.Stderr,
		"This software is a collection of utilities that may be useful\n"+
			"to you when studying at the University of Gothenburg.\n")

	fmt.Fprintln(
		os.Stderr,
		"However, this software has *no official status* and\n"+
			"*no affiliation* or whatsoever with the University of Gothenburg.\n")
}
Ejemplo n.º 4
0
func DoAuth(args []string) {
	// Get params
	var username, password string

	fmt.Printf("Username: "******"%s", &username)

	fmt.Printf("Password: "******"")

	// Make request
	result := Request(&AuthUtility{username, password}).(AuthResult)
	result.SyncPrefs()

	// Show result
	if result.Success {
		fmt.Println(gubase.Color("● Auth succeeded", gubase.ColorGreen))
	} else {
		fmt.Println(gubase.Color("● Auth failed", gubase.ColorRed))
	}
}
Ejemplo n.º 5
0
func usage() {
	fmt.Fprintln(os.Stderr, gubase.Color("** Usage **", gubase.ColorWhite))
	fmt.Fprintln(os.Stderr, "gucli <command> <action>")
}