@@ -87,8 +87,23 @@ def add_arguments(self, parser, cli_name):
87
87
parser .add_argument (
88
88
'--library-name' ,
89
89
help = 'name of the empty library' )
90
-
90
+
91
91
def main (self , * , args ):
92
+
93
+ def get_git_config (key : str ) -> str | None :
94
+ # retrieve a value from git config
95
+ git = shutil .which ('git' )
96
+ if git is not None :
97
+ result = subprocess .run (
98
+ [git , 'config' , key ],
99
+ stdout = subprocess .PIPE ,
100
+ text = True
101
+ )
102
+ value = result .stdout .strip ()
103
+ if value :
104
+ return value
105
+ return None
106
+
92
107
available_licenses = {}
93
108
for shortname , entry in ament_copyright .get_licenses ().items ():
94
109
available_licenses [entry .spdx ] = entry .license_files
@@ -97,39 +112,9 @@ def main(self, *, args):
97
112
print ('Supported licenses:\n %s' % ('\n ' .join (available_licenses )))
98
113
sys .exit (0 )
99
114
100
- git = shutil .which ('git' )
101
-
102
- if args .maintainer_name :
103
- maintainer_name = args .maintainer_name
104
- else :
105
- # try getting the name from the global git config
106
- if git is not None :
107
- p = subprocess .Popen (
108
- [git , 'config' , 'user.name' ],
109
- stdout = subprocess .PIPE )
110
- resp = p .communicate ()
111
- name = resp [0 ].decode ().rstrip ()
112
- if name :
113
- maintainer_name = name
114
- if not maintainer_name :
115
- maintainer_name = getpass .getuser ()
116
-
115
+ maintainer_name : str = args .maintainer_name or get_git_config ('user.name' ) or getpass .getuser ()
117
116
maintainer = Person (maintainer_name )
118
-
119
- if args .maintainer_email :
120
- maintainer .email = args .maintainer_email
121
- else :
122
- # try getting the email from the global git config
123
- if git is not None :
124
- p = subprocess .Popen (
125
- [git , 'config' , 'user.email' ],
126
- stdout = subprocess .PIPE )
127
- resp = p .communicate ()
128
- email = resp [0 ].decode ().rstrip ()
129
- if email :
130
- maintainer .email = email
131
- if not maintainer .email :
132
- maintainer .email = maintainer .name + '@todo.todo'
117
+ maintainer .email = args .maintainer_email or get_git_config ('user.email' ) or f"{ maintainer .name .replace (' ' , '' )} @todo.todo"
133
118
134
119
node_name = None
135
120
library_name = None
0 commit comments