aboutsummaryrefslogtreecommitdiff
path: root/steam-export-cli.go
blob: 46f96dd4bd2e0d19fe98961b1f2379779060b6a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package main

import (
	"errors"
	"flag"
	"fmt"
	"os"

	"git.riedstra.us/mitch/steam-export/steam"
)

var (
	errorHandling flag.ErrorHandling = flag.ExitOnError

	defaultLib string         = "C:\\Program Files (x86)\\Steam\\steamapps"
	steamLib   *steam.Library = &steam.Library{}
)

func parseArgs(args []string) error {
	if len(args) < 2 {
		return errors.New("Not enough arguments")
	}
	switch a := args[1]; a {
	case "list":
		return listGames(args[2:])
	default:
		printHelp()
	}

	return nil
}

func printHelp() {
	fmt.Printf(`Program usage:
steam-export-cli $subcommand $options
Subcommands:
	list -l $steam_library
	package -l $steam_library -f $output_file [ -G $game_index | -g "game_name" ]
	extract -l $steam_library -f $input_file
	delete -l $steam_library [ -G $game_index | -g $game_name ]
	server -c $config_file -l $steam_library -L $listen_addr`)

}

func listGames(args []string) error {
	fl := flag.NewFlagSet("list", errorHandling)
	lib := fl.String("l", defaultLib,
		"Path to library in question. All the way to the 'steamapps' folder")

	l := defaultLib
	fl.Parse(args)
	if fl.Parsed() {
		l = string(*lib)
	}

	if err := steamLib.ProcessLibrary(l); err != nil {
		return err
	}

	fmt.Println(steamLib)

	return nil
}

func main() {
	if err := parseArgs(os.Args); err != nil {
		fmt.Fprintln(os.Stderr, err)
		printHelp()
	}
}