Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit39a4a20

Browse files
author
Gauvain Pocentek
committed
gitlab: autogenerate some doc
1 parent9ca47aa commit39a4a20

File tree

2 files changed

+103
-18
lines changed

2 files changed

+103
-18
lines changed

‎README.md

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,11 +98,15 @@ the action:
9898
gitlab project list
9999
`````
100100

101-
The usable objects are those which inherits GitlabObject (yes, the source is
102-
the doc ATM), with a bit of string transformation (Project => project,
103-
ProjectIssue => project-issue, ...).
101+
Get help with:
104102

105-
The actions are list, get, create, update, delete.
103+
`````
104+
# global help
105+
gitlab --help
106+
107+
# object help
108+
gitlab project help
109+
`````
106110

107111
Some examples:
108112

‎gitlab

Lines changed: 95 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,105 @@
1818

1919
importos
2020
importsys
21+
importre
2122

2223
try:
2324
fromConfigParserimportConfigParser
2425
except:
2526
fromconfigparserimportConfigParser
2627

27-
frominspectimportgetmro
28+
frominspectimportgetmro,getmembers,isclass
2829

2930
importgitlab
3031

32+
camel_re=re.compile('(.)([A-Z])')
33+
3134
defdie(msg):
3235
sys.stderr.write(msg+"\n")
3336
sys.exit(1)
3437

38+
defwhatToCls(what):
39+
return"".join([s.capitalize()forsinwhat.split("-")])
40+
41+
defclsToWhat(cls):
42+
returncamel_re.sub(r'\1-\2',cls.__name__).lower()
43+
44+
defactionHelpList(cls):
45+
l= []
46+
foractionin'list','get','create','update','delete':
47+
attr='can'+action.capitalize()
48+
try:
49+
y=cls.__dict__[attr]
50+
except:
51+
y=gitlab.GitlabObject.__dict__[attr]
52+
ifnoty:
53+
continue
54+
55+
detail=''
56+
ifaction=='list':
57+
detail=" ".join(["--%s=ARG"%xforxincls.requiredListAttrs])
58+
elifactionin ['get','delete']:
59+
detail="--id=ARG "
60+
detail+=" ".join(["--%s=ARG"%xforxincls.requiredGetAttrs])
61+
elifaction=='create':
62+
detail=" ".join(["--%s=ARG"%xforxincls.requiredCreateAttrs])
63+
ifdetail:
64+
detail+=" "
65+
detail+=" ".join(["[--%s=ARG]"%xforxincls.optionalCreateAttrs])
66+
elifaction=='update':
67+
detail=" ".join(["[--%s=ARG]"%xforxincls.requiredCreateAttrs])
68+
ifdetail:
69+
detail+=" "
70+
detail+=" ".join(["[--%s=ARG]"%xforxincls.optionalCreateAttrs])
71+
l.append("%s %s"% (action,detail))
72+
73+
return (l)
74+
75+
defusage():
76+
print("usage: gitlab [--help] [--gitlab=GITLAB] what action [options]")
77+
print("")
78+
print("--gitlab=GITLAB: Specifies which python-gitlab.cfg configuration section should be used.")
79+
print(" If not defined, the default selection will be used.")
80+
print("")
81+
print("--help : Displays this message.")
82+
print("")
83+
print("Available `options` depend on which what/action couple is used.")
84+
print("If `action` is\"help\", available actions and options will be listed for `what`.")
85+
print("")
86+
print("Available `what` values are:")
87+
88+
classes= []
89+
forname,oingetmembers(gitlab):
90+
ifnotisclass(o):
91+
continue
92+
ifgitlab.GitlabObjectingetmro(o)ando!=gitlab.GitlabObject:
93+
classes.append(o)
94+
95+
defs(a,b):
96+
ifa.__name__<b.__name__:
97+
return-1
98+
elifa.__name__>b.__name__:
99+
return1
100+
101+
classes.sort(cmp=s)
102+
forclsinclasses:
103+
print(" %s"%clsToWhat(cls))
104+
105+
35106
gitlab_id=None
36107

37108
args= []
38109
d= {}
39110
forarginsys.argv[1:]:
40111
ifarg.startswith('--'):
112+
arg=arg[2:]
113+
114+
ifarg=='help':
115+
usage()
116+
sys.exit(0)
117+
41118
k,v=arg.split('=',2)
42-
k=k[2:].strip()
119+
k=k.strip()
43120
v=v.strip()
44121

45122
ifk=='gitlab':
@@ -66,23 +143,14 @@ try:
66143
except:
67144
die("Impossible to get gitlab informations from configuration (%s)"%gitlab_id)
68145

69-
try:
70-
gl=gitlab.Gitlab(gitlab_url,private_token=gitlab_token)
71-
gl.auth()
72-
except:
73-
die("Could not connect to GitLab (%s)"%gitlab_url)
74-
75146
try:
76147
what=args.pop(0)
77148
action=args.pop(0)
78149
except:
79150
die("Missing arguments")
80151

81-
ifactionnotin ['get','list','update','create','delete']:
82-
die("Unknown action: %s"%action)
83-
84-
defwhatToCls(what):
85-
return"".join([s.capitalize()forsinwhat.split("-")])
152+
ifactionnotin ['get','list','update','create','delete','help']:
153+
die("Unknown action: %s. Use\"gitlab %s help\" to get details."% (action,what))
86154

87155
try:
88156
cls=gitlab.__dict__[whatToCls(what)]
@@ -92,6 +160,19 @@ except:
92160
ifgitlab.GitlabObjectnotingetmro(cls):
93161
die("Unknown object: %s"%what)
94162

163+
ifaction=="help":
164+
print("%s options:"%what)
165+
foriteminactionHelpList(cls):
166+
print(" %s %s"% (what,item))
167+
168+
sys.exit(0)
169+
170+
try:
171+
gl=gitlab.Gitlab(gitlab_url,private_token=gitlab_token)
172+
gl.auth()
173+
except:
174+
die("Could not connect to GitLab (%s)"%gitlab_url)
175+
95176
ifaction=="create":
96177
ifnotcls.canCreate:
97178
die("%s objects can't be created"%what)
@@ -117,7 +198,7 @@ elif action == "list":
117198

118199
foroinl:
119200
o.pretty_print()
120-
print
201+
print("")
121202

122203
sys.exit(0)
123204

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp