/stdhome

To get this branch, use:
bzr branch http://bzr.ed.am/stdhome

« back to all changes in this revision

Viewing changes to lib/stdhome/command/revert.py

  • Committer: Tim Marston
  • Date: 2014-04-18 15:00:55 UTC
  • Revision ID: tim@ed.am-20140418150055-wy2zmdiwn7sptk4x
status comand now accepts a list of files

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
class RevertCommand( Command ):
30
30
 
31
31
 
 
32
        def __init__( self ):
 
33
                self.all = False
 
34
 
 
35
 
32
36
        def print_help( self ):
33
 
                print "Usage: " + the.program.name + " revert [--repo=REPO] [FILE]..."
 
37
                print "Usage: " + the.program.name + " revert [--repo=REPO] [--all] [FILE]..."
34
38
                print
35
39
                #      01234567890123456789012345678901234567890123456789012345678901234567890123456789
36
40
                print "Revert any local changes to a file in the home directory."
37
41
                print
38
42
                print "This reverts the content of the named files, in the local filesystem, specified"
39
 
                print "relative to the home directory, to its state in the repo."
 
43
                print "relative to the home directory, to its state in the repo.  Specifying individual"
 
44
                print "files and directories will revert them (recursively, in the case of"
 
45
                print "directories).  Or you can revert all files in your home directory by specifying"
 
46
                print "no files and explicitly using the --all option."
40
47
                print
41
48
                print "To see a list files that can be reverted, type:"
42
49
                print "    " + the.program.name + " status"
43
50
                print
44
51
                print "Options:"
 
52
                print "      --all        confirm that you want to revert all files"
45
53
                print "  -r, --repo=REPO  select the repo to check-out or create (defaults to 'home')"
46
54
                print "  -v, --verbose    display information about what is being done"
47
55
                print "      --help       display help and exit"
51
59
        def parse_command_line( self ):
52
60
                opts, args = getopt.gnu_getopt(
53
61
                        sys.argv[ 1: ], "r:v",
54
 
                        [ "repo=", "verbose", "help" ] )
 
62
                        [ "all", "repo=", "verbose", "help" ] )
55
63
                for opt, optarg in opts:
56
 
                        if opt in [ '--repo', '-r' ]:
 
64
                        if opt == "--all":
 
65
                                self.all = True
 
66
                        elif opt in [ '--repo', '-r' ]:
57
67
                                if not re.match( '^[-a-zA-z0-9.]+$', optarg ):
58
68
                                        raise the.program.FatalError(
59
69
                                                'invalid repository name: ' + optarg )
69
79
                # remaining arguments
70
80
                self.files = args
71
81
 
 
82
                # check that either files or --all was given
 
83
                if len( self.files ) == 0 and not self.all:
 
84
                        raise the.program.UsageError(
 
85
                                "no files were specified and --all was not given" )
 
86
                if len( self.files ) > 0 and self.all:
 
87
                        raise the.program.UsageError(
 
88
                                "files specified, which conflicts with using --all" )
 
89
 
72
90
 
73
91
        def run( self ):
74
92