Working on argparse command structure.
This commit is contained in:
parent
f2fba94aa8
commit
ec60f10c40
|
@ -11,31 +11,45 @@ parser = ArgumentParser(description="Manage your weblog via commandline. Creates
|
||||||
parser.add_argument('-d','--blog-dir', dest="blog_dir", default='~/public_html/blog', help='path to blog directory (default: %(default)s)')
|
parser.add_argument('-d','--blog-dir', dest="blog_dir", default='~/public_html/blog', help='path to blog directory (default: %(default)s)')
|
||||||
|
|
||||||
### subroutines of pb
|
### subroutines of pb
|
||||||
subparsers = parser.add_subparsers(help="targets of operation")
|
subparsers = parser.add_subparsers(help="targets of operation", dest='target')
|
||||||
|
|
||||||
|
# 'blog' command
|
||||||
parser_blog = subparsers.add_parser('blog', help='add or update blog or its sections')
|
parser_blog = subparsers.add_parser('blog', help='add or update blog or its sections')
|
||||||
|
|
||||||
## 'blog' subroutines
|
## 'blog' subroutines
|
||||||
subparsers_blog = parser_blog.add_subparsers(help="blog subcommands")
|
subparsers_blog = parser_blog.add_subparsers(help="blog subcommands", dest='action')
|
||||||
parser_update = subparsers_blog.add_parser('update', help='updates blog to current state')
|
blog_parser_update = subparsers_blog.add_parser('update', help='updates blog to current state')
|
||||||
parser_update.add_argument('subsection', choices=['all','recent','archive','feed'], help='sections of blog you may want to update')
|
blog_parser_update.add_argument('subsection', choices=['all','recent','archive','feed'], help='sections of blog you may want to update')
|
||||||
parser_add = subparsers_blog.add_parser("add", help='add an non-existing blog at --blog-dir')
|
blog_parser_add = subparsers_blog.add_parser("add", help='add an non-existing blog at --blog-dir')
|
||||||
|
|
||||||
# 'draft' command
|
# 'draft' command
|
||||||
parser_draft = subparsers.add_parser('draft', help='create, list, edit or remove drafts')
|
parser_draft = subparsers.add_parser('draft', help='create, list, edit or remove drafts')
|
||||||
parser_draft.add_argument('action', choices=['add','list','edit','remove'], help='define what to do with a certain draft')
|
## 'draft' subroutines
|
||||||
parser_draft.add_argument('nameorid', choices=['name','id'], help='define an alphanumeric name for draft or the database id specified by [list]')
|
subparsers_draft = parser_draft.add_subparsers(help="draft subcommands", dest='action')
|
||||||
|
draft_parser_add = subparsers_draft.add_parser('add', help='add a new draft')
|
||||||
|
draft_parser_add.add_argument('name', help='define an alphanumeric name')
|
||||||
|
draft_parser_list = subparsers_draft.add_parser('list', help='list drafts')
|
||||||
|
draft_parser_edit = subparsers_draft.add_parser('edit', help='edit certain draft')
|
||||||
|
draft_parser_edit.add_argument('id', help='id like specified by [list]')
|
||||||
|
draft_parser_remove = subparsers_draft.add_parser('remove', help='remove certain draft')
|
||||||
|
draft_parser_remove.add_argument('id', help='id like specified by [list]')
|
||||||
|
|
||||||
# 'article' command
|
# 'article' command
|
||||||
parser_article = subparsers.add_parser('article', help='import, list, edit or delete article')
|
parser_article = subparsers.add_parser('article', help='import, list, edit or delete article')
|
||||||
|
|
||||||
|
## 'article' subroutines
|
||||||
|
subparsers_article = parser_article.add_subparsers(help="article subcommands", dest='action')
|
||||||
|
article_parser_add = subparsers_article.add_parser('add', help='add a new article')
|
||||||
|
article_parser_add.add_argument('name', help='define an alphanumeric name')
|
||||||
|
article_parser_list = subparsers_article.add_parser('list', help='list articles')
|
||||||
|
article_parser_edit = subparsers_article.add_parser('edit', help='edit certain article')
|
||||||
|
article_parser_edit.add_argument('id', help='id like specified by [list]')
|
||||||
|
article_parser_remove = subparsers_article.add_parser('remove', help='remove certain article')
|
||||||
|
article_parser_remove.add_argument('id', help='id like specified by [list]')
|
||||||
|
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
print(args)
|
print(args)
|
||||||
args_blog = parser_blog.parse_args()
|
|
||||||
print(args_blog)
|
|
||||||
args_draft = parser_draft.parse_args()
|
|
||||||
print(args_draft)
|
|
||||||
args_article = parser_article.parse_args()
|
|
||||||
|
|
||||||
# set path to blog
|
# set path to blog
|
||||||
try:
|
try:
|
||||||
|
@ -122,6 +136,42 @@ def update_blog():
|
||||||
with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
with open(blogIndex,"w", encoding=l10nconf['BLOG_CHARSET']) as f:
|
||||||
print(tmpIndex, file=f)
|
print(tmpIndex, file=f)
|
||||||
|
|
||||||
if vars(args)['update']:
|
|
||||||
print("Updating your block.")
|
if vars(args)['target'] == 'blog':
|
||||||
update_blog()
|
|
||||||
|
if vars(args)['action'] == 'update':
|
||||||
|
print("Updating your block.")
|
||||||
|
update_blog()
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'add':
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if vars(args)['target'] == 'draft':
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'add':
|
||||||
|
pass
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'list':
|
||||||
|
pass
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'edit':
|
||||||
|
pass
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'remove':
|
||||||
|
pass
|
||||||
|
|
||||||
|
if vars(args)['target'] == 'article':
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'add':
|
||||||
|
pass
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'list':
|
||||||
|
pass
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'edit':
|
||||||
|
pass
|
||||||
|
|
||||||
|
if vars(args)['action'] == 'remove':
|
||||||
|
|
||||||
|
pass
|
||||||
|
|
Loading…
Reference in New Issue