# HG changeset patch # User Andreas Nolda # Date 1587740889 -7200 # Fri Apr 24 17:08:09 2020 +0200 # Node ID c3cb85d3f98eeedd69c27dfac213f06f691d6787 # Parent 919e9286c6d3bd1ba7ad1c5c0ce16cfeea5eb88b add option "-n" ("--line-number") diff --git a/ChangeLog.md b/ChangeLog.md --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,3 +1,10 @@ +2020-04-24: + +* rename option `-n` (`--declare-ns`) to `-N` +* add option `-n` (`--line-number`) +* bump version to 2.7 + + 2020-01-14: * catch keyboard interrupt diff --git a/README.md b/README.md --- a/README.md +++ b/README.md @@ -27,7 +27,8 @@ [-l] [--files-with-matches] [-L] [--files-without-match] [-m] [--matches] - [-n] [--declare-ns] + [-n] [--line-number] + [-N] [--declare-ns] [-q] [--quiet] [-r ] [--regex ] @@ -47,9 +48,9 @@ output through [GNU less](http://www.gnu.org/software/less/) and similar programs. -The options `-c`, `-l`, `-L`, and `-q` mimic the behaviour of -[GNU grep](http://www.gnu.org/software/grep/). The latter option suppresses any -output, but still returns the exit status (`0` if there are matches, `1` if +The options `-c`, `-l`, `-L`, `-n`, and `-q` mimic the behaviour +of [GNU grep](http://www.gnu.org/software/grep/). The latter option suppresses +any output, but still returns the exit status (`0` if there are matches, `1` if there are none, and `2` for errors). Andreas Nolda (andreas@nolda.org) diff --git a/xgrep.py b/xgrep.py --- a/xgrep.py +++ b/xgrep.py @@ -1,6 +1,6 @@ #! /usr/bin/python3 # xgrep.py -- search for elements in XML files, using XPath 1.0 expressions -# Andreas Nolda 2020-01-14 +# Andreas Nolda 2020-04-24 import sys import argparse @@ -8,7 +8,7 @@ from blessings import Terminal from lxml import etree -version=2.6 +version=2.7 parser = argparse.ArgumentParser() parser.add_argument("expr", @@ -27,7 +27,9 @@ help="output list of non-matching files") parser.add_argument("-m", "--matches", action="store_true", help="output list of matches") -parser.add_argument("-n", "--declare-ns", action="store_true", +parser.add_argument("-n", "--line-number", action="store_true", + help="output line number of match start") +parser.add_argument("-N", "--declare-ns", action="store_true", help="declare namespaces in matches") parser.add_argument("-q", "--quiet", action="store_true", help="only return exit status") @@ -94,6 +96,8 @@ print(term.bold("{0}[{1}]".format(args.expr, int)) + ":") else: print(term.bold(args.expr) + ":") + if args.line_number: + print(term.bright_black("{0}".format(match.sourceline)) + ":", end="") if args.declare_ns: print(serialize_match(match)) else: