Permalink
Browse files

Logcat command line arguments need to be ordered: flags, then filters.

…fixes #5
  • Loading branch information...
marshall committed Nov 26, 2012
1 parent 2254648 commit 569c6ec38a33a22cbbd22ab98581490ece1241ed
Showing with 27 additions and 5 deletions.
  1. +6 −5 logcat-color
  2. +21 −0 test/logcat_color_test.py
View
@@ -23,8 +23,8 @@ from logcatcolor.profile import Profile
from logcatcolor.reader import LogcatReader
class LogcatColor(object):
- def __init__(self):
- self.parse_args()
+ def __init__(self, args=None):
+ self.parse_args(args)
self.width = self.get_term_width()
self.config = LogcatColorConfig(self.options)
@@ -59,7 +59,7 @@ class LogcatColor(object):
return width
- def parse_args(self):
+ def parse_args(self, args=None):
parser = optparse.OptionParser()
# logcat-color options
@@ -122,7 +122,7 @@ class LogcatColor(object):
" brief, process, tag, raw, time, threadtime, long" +
" (default: brief)")
- (options, args) = parser.parse_args()
+ (options, args) = parser.parse_args(args)
self.options = options
self.args = args
@@ -185,7 +185,8 @@ class LogcatColor(object):
def get_logcat_args(self):
logcat_args = self.logcat_args[:]
if self.format:
- logcat_args.extend(["-v", self.format])
+ # put format in front in case custom filters are used
+ logcat_args[0:0] = ["-v", self.format]
return logcat_args
def start(self):
View
@@ -8,6 +8,7 @@
this_dir = os.path.dirname(os.path.abspath(__file__))
logcat_color = os.path.join(os.path.dirname(this_dir), "logcat-color")
+execfile(logcat_color)
def logcat_color_test(*args, **kwargs):
def run_logcat_color_test(fn):
@@ -135,4 +136,24 @@ def test_file_output(self):
out_data = open(tmpout, "r").read()
self.assertEqual(out_data, brief_data)
+ def test_logcat_options_with_filters(self):
+ # Make sure logcat flags come before filter arguments
+ # https://github.com/marshall/logcat-color/issues/5
+ lc = LogcatColor(args=["-v", "time", "Tag1:V", "*:S", "--silent",
+ "--print-size", "--dump", "--clear"])
+ self.assertEqual(lc.format, "time")
+ args = lc.get_logcat_args()
+
+ self.assertEqual(len(args), 8)
+
+ format_index = args.index("-v")
+ self.assertTrue(format_index >= 0)
+ self.assertEqual(args[format_index+1], "time")
+ self.assertTrue("-s" in args)
+ self.assertTrue("-d" in args)
+ self.assertTrue("-g" in args)
+ self.assertTrue("-c" in args)
+
+ self.assertEqual(args[-2], "Tag1:V")
+ self.assertEqual(args[-1], "*:S")

2 comments on commit 569c6ec

Thanks for the quick resolution 👍

Owner

marshall replied Nov 26, 2012

@naseer welcome -- I just pushed out v0.5 that includes this fix as well :)

Please sign in to comment.