Uh oh!
There was an error while loading. Please reload this page.
forked from github-release/github-release
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub-release.go
More file actions
Latest commit
143 lines (126 loc) · 7.15 KB
/
Copy pathgithub-release.go
File metadata and controls
143 lines (126 loc) · 7.15 KB
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
package main
import (
"fmt"
"os"
"github.com/github-release/github-release/github"
"github.com/voxelbrain/goptions"
)
constGH_URL="https://github.com"
typeOptionsstruct {
Help goptions.Help`goptions:"-h, --help, description='Show this help'"`
Verbosity []bool`goptions:"-v, --verbose, description='Be verbose'"`
Quietbool`goptions:"-q, --quiet, description='Do not print anything, even errors (except if --verbose is specified)'"`
Versionbool`goptions:"--version, description='Print version'"`
goptions.Verbs
Downloadstruct {
Tokenstring`goptions:"-s, --security-token, description='Github token ($GITHUB_TOKEN if set). required if repo is private.'"`
Userstring`goptions:"-u, --user, description='Github repo user or organisation (required if $GITHUB_USER not set)'"`
AuthUserstring`goptions:"-a, --auth-user, description='Username for authenticating to the API (falls back to $GITHUB_AUTH_USER or $GITHUB_USER)'"`
Repostring`goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
Latestbool`goptions:"-l, --latest, description='Download latest release (required if tag is not specified)',mutexgroup='input'"`
Tagstring`goptions:"-t, --tag, description='Git tag to download from (required if latest is not specified)', mutexgroup='input',obligatory"`
Namestring`goptions:"-n, --name, description='Name of the file', obligatory"`
} `goptions:"download"`
Uploadstruct {
Tokenstring`goptions:"-s, --security-token, description='Github token (required if $GITHUB_TOKEN not set)'"`
Userstring`goptions:"-u, --user, description='Github repo user or organisation (required if $GITHUB_USER not set)'"`
AuthUserstring`goptions:"-a, --auth-user, description='Username for authenticating to the API (falls back to $GITHUB_AUTH_USER or $GITHUB_USER)'"`
Repostring`goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
Tagstring`goptions:"-t, --tag, description='Git tag to upload to', obligatory"`
Namestring`goptions:"-n, --name, description='Name of the file', obligatory"`
Labelstring`goptions:"-l, --label, description='Label (description) of the file'"`
File*os.File`goptions:"-f, --file, description='File to upload (use - for stdin)', rdonly, obligatory"`
Replacebool`goptions:"-R, --replace, description='Replace asset with same name if it already exists (WARNING: not atomic, failure to upload will remove the original asset too)'"`
} `goptions:"upload"`
Releasestruct {
Tokenstring`goptions:"-s, --security-token, description='Github token (required if $GITHUB_TOKEN not set)'"`
Userstring`goptions:"-u, --user, description='Github repo user or organisation (required if $GITHUB_USER not set)'"`
Repostring`goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
Tagstring`goptions:"-t, --tag, obligatory, description='Git tag to create a release from'"`
Namestring`goptions:"-n, --name, description='Name of the release (defaults to tag)'"`
Descstring`goptions:"-d, --description, description='Release description, use - for reading a description from stdin (defaults to tag)'"`
Targetstring`goptions:"-c, --target, description='Commit SHA or branch to create release of (defaults to the repository default branch)'"`
Draftbool`goptions:"--draft, description='The release is a draft'"`
Prereleasebool`goptions:"-p, --pre-release, description='The release is a pre-release'"`
} `goptions:"release"`
Editstruct {
Tokenstring`goptions:"-s, --security-token, description='Github token (required if $GITHUB_TOKEN not set)'"`
Userstring`goptions:"-u, --user, description='Github repo user or organisation (required if $GITHUB_USER not set)'"`
AuthUserstring`goptions:"-a, --auth-user, description='Username for authenticating to the API (falls back to $GITHUB_AUTH_USER or $GITHUB_USER)'"`
Repostring`goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
Tagstring`goptions:"-t, --tag, obligatory, description='Git tag to edit the release of'"`
Namestring`goptions:"-n, --name, description='New name of the release (defaults to tag)'"`
Descstring`goptions:"-d, --description, description='New release description, use - for reading a description from stdin (defaults to tag)'"`
Draftbool`goptions:"--draft, description='The release is a draft'"`
Prereleasebool`goptions:"-p, --pre-release, description='The release is a pre-release'"`
} `goptions:"edit"`
Deletestruct {
Tokenstring`goptions:"-s, --security-token, description='Github token (required if $GITHUB_TOKEN not set)'"`
Userstring`goptions:"-u, --user, description='Github repo user or organisation (required if $GITHUB_USER not set)'"`
AuthUserstring`goptions:"-a, --auth-user, description='Username for authenticating to the API (falls back to $GITHUB_AUTH_USER or $GITHUB_USER)'"`
Repostring`goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
Tagstring`goptions:"-t, --tag, obligatory, description='Git tag of release to delete'"`
} `goptions:"delete"`
Infostruct {
Tokenstring`goptions:"-s, --security-token, description='Github token ($GITHUB_TOKEN if set). required if repo is private.'"`
Userstring`goptions:"-u, --user, description='Github repo user or organisation (required if $GITHUB_USER not set)'"`
AuthUserstring`goptions:"-a, --auth-user, description='Username for authenticating to the API (falls back to $GITHUB_AUTH_USER or $GITHUB_USER)'"`
Repostring`goptions:"-r, --repo, description='Github repo (required if $GITHUB_REPO not set)'"`
Tagstring`goptions:"-t, --tag, description='Git tag to query (optional)'"`
JSONbool`goptions:"-j, --json, description='Emit info as JSON instead of text'"`
} `goptions:"info"`
}
typeCommandfunc(Options) error
varcommands=map[goptions.Verbs]Command{
"download": downloadcmd,
"upload": uploadcmd,
"release": releasecmd,
"edit": editcmd,
"delete": deletecmd,
"info": infocmd,
}
var (
VERBOSITY=0
)
var (
// The user whose token is being used to authenticate to the API. If unset,
// EnvUser is used.
EnvAuthUserstring
EnvTokenstring
EnvUserstring
EnvRepostring
EnvApiEndpointstring
)
funcinit() {
EnvToken=os.Getenv("GITHUB_TOKEN")
EnvUser=os.Getenv("GITHUB_USER")
EnvAuthUser=os.Getenv("GITHUB_AUTH_USER")
EnvRepo=os.Getenv("GITHUB_REPO")
EnvApiEndpoint=os.Getenv("GITHUB_API")
ifEnvAuthUser=="" {
EnvAuthUser=EnvUser
}
}
funcmain() {
options:=Options{}
goptions.ParseAndFail(&options)
ifoptions.Version {
fmt.Printf("github-release v%s\n", github.VERSION)
return
}
iflen(options.Verbs) ==0 {
goptions.PrintHelp()
return
}
VERBOSITY=len(options.Verbosity)
github.VERBOSITY=VERBOSITY
ifcmd, found:=commands[options.Verbs]; found {
err:=cmd(options)
iferr!=nil {
if!options.Quiet {
fmt.Fprintln(os.Stderr, "error:", err)
}
os.Exit(1)
}
}
}