Merge lp:~ack/apt-btrfs-snapshot/fix-arg-parser into lp:apt-btrfs-snapshot

Proposed by Alberto Donato
Status: Needs review
Proposed branch: lp:~ack/apt-btrfs-snapshot/fix-arg-parser
Merge into: lp:apt-btrfs-snapshot
Diff against target: 54 lines (+2/-10)
1 file modified
apt-btrfs-snapshot (+2/-10)
To merge this branch: bzr merge lp:~ack/apt-btrfs-snapshot/fix-arg-parser
Reviewer Review Type Date Requested Status
Michael Vogt Approve
Review via email: mp+328776@code.launchpad.net

Description of the change

This fixes the argparse setup not to error if no command is provided:

$ sudo apt-btrfs-snapshot
Traceback (most recent call last):
  File "/usr/bin/apt-btrfs-snapshot", line 98, in <module>
    if args.command == "supported":
AttributeError: 'Namespace' object has no attribute 'command'

by setting the command parameter as required.

To post a comment you must log in.
Revision history for this message
Michael Vogt (mvo) wrote :

Looks great, thanks for working on this!

review: Approve
Revision history for this message
Alberto Donato (ack) wrote :

@mvo can this be merged?

Unmerged revisions

55. By Alberto Donato

Fix ArgumentParser setup.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'apt-btrfs-snapshot'
2--- apt-btrfs-snapshot 2015-10-16 09:27:08 +0000
3+++ apt-btrfs-snapshot 2017-08-09 14:50:33 +0000
4@@ -42,39 +42,33 @@
5 parser = argparse.ArgumentParser(description=description)
6 parser.add_argument("--debug", action="store_true", default=False,
7 help="enable debug output")
8- subparser = parser.add_subparsers(title="Commands")
9+ subparser = parser.add_subparsers(dest="command", metavar="command")
10+ subparser.required = True
11 # supported
12 command = subparser.add_parser(
13 "supported", help=_("Print if snapshots are supported"))
14- command.set_defaults(command="supported")
15 # list
16 command = subparser.add_parser(
17 "list", help=_("List available snapshots"))
18- command.set_defaults(command="list")
19 # snapshot
20 command = subparser.add_parser(
21 "snapshot", help=_("Create a new snapshot"))
22- command.set_defaults(command="snapshot")
23 # set-default
24 command = subparser.add_parser(
25 "set-default", help=_("Revert to previous snapshot"))
26 command.add_argument("snapshot")
27- command.set_defaults(command="set-default")
28 # delete
29 command = subparser.add_parser(
30 "delete", help=_("Delete snapshot"))
31 command.add_argument("snapshot")
32- command.set_defaults(command="delete")
33 # list-older-than
34 command = subparser.add_parser(
35 "list-older-than", help=_("Show snapshots older than N days"))
36 command.add_argument("time")
37- command.set_defaults(command="list-older-than")
38 # delete-older-than
39 command = subparser.add_parser(
40 "delete-older-than", help=_("Delete snapshots older than N days"))
41 command.add_argument("time")
42- command.set_defaults(command="delete-older-than")
43
44 # parse args
45 args = parser.parse_args()
46@@ -113,8 +107,6 @@
47 res = apt_btrfs.print_btrfs_root_snapshots_older_than(args.time)
48 elif args.command == "delete-older-than":
49 res = apt_btrfs.clean_btrfs_root_snapshots_older_than(args.time)
50- else:
51- print(_("ERROR: Unhandled command: '%s'") % args.command)
52
53 # return the right exit code
54 if res:

Subscribers

People subscribed via source and target branches

to all changes: