write switch for remove
This commit is contained in:
@@ -242,6 +242,7 @@ def remove_share(shares,config,opts):
|
|||||||
print("Removing share: %s"%( name, ))
|
print("Removing share: %s"%( name, ))
|
||||||
print(json.dumps(share_, indent = 2, sort_keys = True))
|
print(json.dumps(share_, indent = 2, sort_keys = True))
|
||||||
|
|
||||||
|
if opts.write:
|
||||||
shares = [share for share in shares if share['name'] != name]
|
shares = [share for share in shares if share['name'] != name]
|
||||||
|
|
||||||
shares_file = os.path.join(config['__root_path__'], opts.shares_file)
|
shares_file = os.path.join(config['__root_path__'], opts.shares_file)
|
||||||
@@ -250,6 +251,8 @@ def remove_share(shares,config,opts):
|
|||||||
with open(shares_file,'wt') as fp:
|
with open(shares_file,'wt') as fp:
|
||||||
json.dump(shares, fp, indent = 2, sort_keys = True)
|
json.dump(shares, fp, indent = 2, sort_keys = True)
|
||||||
print("Removed %s from %s"%(name, shares_file))
|
print("Removed %s from %s"%(name, shares_file))
|
||||||
|
else:
|
||||||
|
print("Share was not actually removed. Use -w to rewrite shares file.")
|
||||||
|
|
||||||
|
|
||||||
def print_rest_api(shares, config, opts):
|
def print_rest_api(shares, config, opts):
|
||||||
@@ -371,6 +374,9 @@ def parse_options():
|
|||||||
## Remove
|
## Remove
|
||||||
parser_remove = subparsers.add_parser('remove', help = "Remove a share")
|
parser_remove = subparsers.add_parser('remove', help = "Remove a share")
|
||||||
parser_remove.add_argument(dest="name")
|
parser_remove.add_argument(dest="name")
|
||||||
|
parser_remove.add_argument('-w','--write', action="store_true", dest="write", default = False,
|
||||||
|
help = "Write changes to the shares.json file"
|
||||||
|
)
|
||||||
## Add
|
## Add
|
||||||
parser_add = subparsers.add_parser('add', help = "Add a share")
|
parser_add = subparsers.add_parser('add', help = "Add a share")
|
||||||
parser_add.add_argument('-n','--name', action="store", dest="name", required = True)
|
parser_add.add_argument('-n','--name', action="store", dest="name", required = True)
|
||||||
|
|||||||
Reference in New Issue
Block a user