Parcourir la source

[add][Fix #15] removed -f prepending input name

isundil il y a 9 ans
Parent
commit
875b8385b5
2 fichiers modifiés avec 33 ajouts et 24 suppressions
  1. 14 5
      doc/jsonstroll.1
  2. 19 19
      src/params.cpp

+ 14 - 5
doc/jsonstroll.1

@@ -1,18 +1,27 @@
 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.47.3.
-.TH JSONSTROLL "1" "August 2016" "jsonstroll (jsonstroller suite) 1.0RC1 generated on Aug  6 2016" "User Commands"
+.TH JSONSTROLL "1" "August 2016" "jsonstroll (jsonstroller suite) 1.0RC1 generated on Aug  7 2016" "User Commands"
 .SH NAME
-jsonstroll \- manual page for jsonstroll (jsonstroller suite) 1.0RC1 generated on Aug  6 2016
+jsonstroll \- manual page for jsonstroll (jsonstroller suite) 1.0RC1 generated on Aug  7 2016
 .SH SYNOPSIS
 .B jsonstroll
-[\fI\,OPTIONS\/\fR] [\fI\,--\/\fR] \fI\,INPUT\/\fR
+[\fI\,OPTIONS\/\fR]
+.br
+.B jsonstroll
+[\fI\,OPTIONS\/\fR] \fI\,FILENAME\/\fR
+.br
+.B jsonstroll
+[\fI\,OPTIONS\/\fR] \fI\,-- INPUT\/\fR
 .SH DESCRIPTION
 Read json input and print it using ncurse
 .PP
-if not INPUT nor \fB\-f\fR, use standard input
+if not INPUT nor FILENAME, use standard input
 .TP
-\fB\-f\fR filename
+FILENAME
 read input from filename instead of stdin
 .TP
+INPUT
+use this as input instead of stdin
+.TP
 \fB\-W\fR
 consider continuing on non\-blocking errors
 .TP

+ 19 - 19
src/params.cpp

@@ -35,21 +35,7 @@ bool Params::read()
         std::string tmp(*i);
         if (!input)
         {
-            if (tmp == "-f")
-            {
-                i++;
-                if (i == params.cend())
-                    throw std::runtime_error("Invalid use of -f without argument");
-                tmp = *i;
-                std::ifstream *in = new std::ifstream(tmp);
-                if (!in->is_open())
-                {
-                    delete in;
-                    throw std::runtime_error("Cannot open " +tmp +" for reading");
-                }
-                this->input = in;
-            }
-            else if (tmp == "--")
+            if (tmp == "--")
             {
                 input = new std::stringstream();
             }
@@ -79,8 +65,18 @@ bool Params::read()
                 else
                     throw std::runtime_error("Invalid option for --color: " +mode);
             }
-            else
+            else if (tmp.find("-") == 0)
                 throw std::runtime_error("Invalid argument: " +tmp);
+            else
+            {
+                std::ifstream *in = new std::ifstream(tmp);
+                if (!in->is_open())
+                {
+                    delete in;
+                    throw std::runtime_error("Cannot open " +tmp +" for reading");
+                }
+                this->input = in;
+            }
         }
         else
         {
@@ -111,11 +107,15 @@ std::basic_istream<char> &Params::getInput() const
 
 void Params::usage() const noexcept
 {
-    std::cout << "Usage: " << progName << " [OPTIONS] [--] INPUT" << std::endl
+    std::cout << "Usage: "
+    << progName << " [OPTIONS]" << std::endl
+    << "or: " << progName << " [OPTIONS] FILENAME" << std::endl
+    << "or: " << progName << " [OPTIONS] -- INPUT" << std::endl
     << "Read json input and print it using ncurse" << std::endl << std::endl
-    << "if not INPUT nor -f, use standard input" << std::endl << std::endl
+    << "if not INPUT nor FILENAME, use standard input" << std::endl << std::endl
 
-    << "  -f filename\t\tread input from filename instead of stdin" << std::endl
+    << "  FILENAME\t\tread input from filename instead of stdin" << std::endl
+    << "  INPUT\t\tuse this as input instead of stdin" << std::endl
     << "  -W \t\t\tconsider continuing on non-blocking errors" << std::endl
     << "  --ascii\t\tignore unicode values" << std::endl
     << "  --color[=MODE]\tcolorize output, MODE can be never or always (default when ommited)" << std::endl