aboutsummaryrefslogtreecommitdiff
path: root/patchodon.py
blob: dc4d0fdd4521228ae5f8a161c533ba344a49400f (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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/env python3

import sys, os
import argparse
import requests

VERSION = "0.1.0"


def main():
    ap = argparse.ArgumentParser(
        prog=sys.argv[0],
        epilog="patchodon.py version " + VERSION + " is a free software.",
        description="Publicly send and receive git patch series via Mastodon.",
    )

    cmds = ap.add_subparsers(required=True, dest="command")

    if "POST command":
        post = cmds.add_parser("post")
        if "API token sources":
            group = post.add_mutually_exclusive_group()
            group.add_argument(
                "--debug-api-token",
                help=(
                    "specify the API token (not very secure, good for debugging"
                    " only)"
                ),
            )
            group.add_argument(
                "-e",
                "--env-api-token",
                action="store_true",
                help="get the API token from environment PATCHODON_API_TOKEN",
            )

        post.add_argument(
            "-i", "--instance-url", help="mastodon instance URL to post to"
        )
        post.add_argument(
            "-r", "--recipient", help="recipient to tag in the initial post"
        )
        post.add_argument(
            "patchfile",
            nargs="*",
            help=(
                "filenames of the patch series; taken from stdin if none are"
                " specified (useful for piping the output of git-format-patch"
                " into patchodon)"
            ),
        )

    if "GET command":
        get = cmds.add_parser("get")
        get.add_argument(
            "patch_url",
            help=(
                "root URL of the status where the patch was posted (the status"
                " should contain the patch hash)"
            ),
        )
        if "output possibilities":
            group = get.add_mutually_exclusive_group()
            group.add_argument(
                "-a",
                "--am",
                help=(
                    "apply the patches immediately with git-am instead of"
                    " storing them in a directory"
                ),
            )
            group.add_argument(
                "-C",
                "--out-dir",
                help=(
                    "output the patches into a given directory (by default, `.'"
                ),
            )
            get.add_argument(
                "--overwrite",
                action="store_true",
                help="overwrite existing patch files instead of renaming",
            )

    ap.add_argument(
        "-c",
        "--config",
        help=(
            "specify a custom config INI file (it can specify a section"
            " [patchodon] with keys instance_url and api_token), defaults to"
            " `$HOME/.patchodon.ini'; specify /dev/null to avoid reading"
            " configs"
        ),
    )
    args = ap.parse_args()
    print(args)


if __name__ == "__main__":
    main()