(argv)
| 126 | sys.exit(code) |
| 127 | |
| 128 | def main(argv): |
| 129 | # XXX add support for branching |
| 130 | # XXX support .N for output |
| 131 | if len(argv) <= 1: |
| 132 | talkback(help_msg, code=0) |
| 133 | if len(argv) < 3: |
| 134 | talkback('Not enough arguments. Need a command and filename.', help=True) |
| 135 | command = argv[1].lower() |
| 136 | if command not in 'log extract diff add update l e d a u'.split(): |
| 137 | talkback('Unknown command: ' + command, help=True) |
| 138 | command = command[:1] |
| 139 | filename = argv[2] |
| 140 | repo_fn = get_repo_fn(filename) |
| 141 | |
| 142 | if command in 'le': |
| 143 | if not os.path.exists(repo_fn): |
| 144 | talkback(repo_fn + ' not found') |
| 145 | v = int(argv[3]) if len(argv) >= 4 else None |
| 146 | if command == 'l': |
| 147 | print_log(repo_fn, v) |
| 148 | else: |
| 149 | print get_version(repo_fn, v), |
| 150 | elif command == 'd': |
| 151 | v1 = int(argv[3]) if len(argv) >= 4 else None |
| 152 | v2 = int(argv[4]) if len(argv) >= 5 else filename |
| 153 | print diff(repo_fn, v1, v2, context=True), |
| 154 | elif command in 'au': |
| 155 | if not os.path.exists(filename): |
| 156 | talkback('Cannot find file: ' + filename) |
| 157 | d = diff(repo_fn, None, filename) |
| 158 | if len(d.splitlines()) == 1: |
| 159 | talkback('File is already current. There are no changes.', code=0) |
| 160 | msg = ' '.join(argv[3:]) |
| 161 | create = not os.path.exists(repo_fn) |
| 162 | repo_file = open(repo_fn, 'a+') |
| 163 | print >> repo_file, make_header(filename, msg, create) |
| 164 | print >> repo_file, d, |
| 165 | repo_file.close() |
| 166 | talkback('Added to ' + repo_fn, code=0) |
| 167 | else: |
| 168 | talkback('Unreachable') |
| 169 | |
| 170 | |
| 171 | if __name__ == '__main__': |
no test coverage detected