summaryrefslogtreecommitdiffstats
path: root/gamechestcli/__main__.py
blob: 8452b99c4907b8001c4c2990e164f6e30b452dad (plain)
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
#!/usr/bin/python3
'''
Manage games. Install, remove, run them.

Usage: gamechest install <GAME_ID>
       gamechest remove <GAME_ID>
       gamechest run [--profile_id=<PROFILE_ID>] <GAME_ID>
       gamechest set [--profile_id=<PROFILE_ID>] [--remote_basedir=<PATH>] [--gamesaves_path=<PATH>]
       gamechest list [--installed|--not-installed]
       gamechest showconfig

Options:
  --profile_id=<PROFILE_ID>, -p <PROFILE_ID>
        use profile <PROFILE_ID> instead of the default one.
'''

import sys

import docopt
from rich import print

from gamechest.cliactions import install, remove, run
from gamechest.gameconfig import config
from gamechest.statusdb import StatusDB
from gamechest.gamedb import GameDB


def main():
    args = docopt.docopt(__doc__)
    #print(args); raise SystemExit(0)

    if args['install']:
        install.install(args['<GAME_ID>'])
    elif args['remove']:
        remove.remove(args['<GAME_ID>'])
    elif args['run']:
        profile_id = args['--profile_id'] or config.get_profile_id()
        if not profile_id:
            print('profile_id must be not null', file=sys.stderr)
        run.run(args['<GAME_ID>'], profile_id)
    elif args['set']:
        if args['--profile_id']:
            config.set_profile_id(args['--profile_id'])
        if args['--remote_basedir']:
            config.set_remote_basedir(args['--remote_basedir'])
        if args['--gamesaves_path']:
            config.set_gamesaves_path(args['--gamesaves_path'])
        config.save()
    elif args['list']:
        status_db = StatusDB()
        if args['--installed']:
            print(list(status_db.get_installed()))
        else:
            game_db = GameDB()
            list_installed = list(status_db.get_installed())
            for game_id in game_db.get_ids():
                if args['--not-installed']:
                    if game_id not in list_installed:
                        print(game_id)
                else:
                    print(game_id, 'installed:', game_id in list_installed)
    elif args['showconfig']:
        config.print_config()


if __name__ == "__main__":
    main()