Skip to content

Commit 23b091f

Browse files
committed
✨ support for udpating acces tokens through the config
1 parent 03eaa2b commit 23b091f

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

code_counter/conf/config.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ def invoke(self, args):
4343
if args.restore:
4444
self.restore()
4545
else:
46+
if any([args.github_token, args.gitee_token]):
47+
self.__update_access_token(args.github_token, args.gitee_token)
4648
if any([args.suffix_reset, args.comment_reset, args.ignore_reset]):
4749
self.__reset_config(args.suffix_reset, args.comment_reset, args.ignore_reset)
4850
if any([args.suffix_add, args.comment_add, args.ignore_add]):
@@ -59,6 +61,16 @@ def __confirm(self, tips):
5961
check = input(tips)
6062
return check.strip().lower() == 'y'
6163

64+
def __update_access_token(self, github_access_token, gitee_access_token):
65+
if github_access_token:
66+
if self.__confirm("the old Github access token will be updated to `{}` . (y/n) ".format(github_access_token)):
67+
self.access_tokens.github = github_access_token
68+
if gitee_access_token:
69+
if self.__confirm("the old Gitee access token will be updated to `{}` . (y/n) ".format(gitee_access_token)):
70+
self.access_tokens.gitee = gitee_access_token
71+
72+
self.__update()
73+
6274
def __reset_config(self, suffix_reset, comment_reset, ignore_reset):
6375
if suffix_reset:
6476
if self.__confirm("'suffix' will be replaced with {} . (y/n) ".format(suffix_reset)):

code_counter/core/args.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,11 @@ def __config(self):
177177
parser.add_argument('--ignore-del', dest='ignore_del', type=split_args,
178178
help="delete some values of the 'ignore' in the config")
179179

180+
parser.add_argument('--github-token', dest='github_token',
181+
help="update the Github access token")
182+
parser.add_argument('--gitee-token', dest='gitee_token',
183+
help="update the Gitee access token")
184+
180185
parser.add_argument('--restore', dest='restore', action='store_true',
181186
help="restore default config")
182187

0 commit comments

Comments
 (0)