diff src/entai_app/entai_app.go @ 1:3dafd57af3b1

bug-fix.
author pyon@macmini
date Thu, 06 Oct 2016 00:55:26 +0900
parents de451fa0c9cd
children 451c99c1d9de
line wrap: on
line diff
--- a/src/entai_app/entai_app.go	Sat Oct 01 11:16:31 2016 +0900
+++ b/src/entai_app/entai_app.go	Thu Oct 06 00:55:26 2016 +0900
@@ -1,15 +1,17 @@
 /****************************************************************************/
-/* Entai_app.go ( ver 0.1 )                                                 */
-/*                                    Last Change: 2016-09-30 Fri 22:09:50. */
+/* Entai_app.go ( ver 0.2 )                                                 */
+/*                                    Last Change: 2016-10-06 Thu 00:49:10. */
 /****************************************************************************/
 
 package main
 
 import (
+    "bufio"
     "flag"
     "fmt"
     "os"
     "strconv"
+    "strings"
     "time"
 
     "entai"
@@ -23,10 +25,12 @@
     h := flag.Bool( "h", false, "help" )
     r := flag.Bool( "r", false, "print rate" )
     l := flag.Bool( "l", false, "1-liner mode" )
+    b := flag.Bool( "b", false, "batch mode" )
     v := flag.Bool( "v", false, "print verbose in 1-liner mode")
-    i := flag.Bool( "i", false, "print input in 1-liner mode")
+    i := flag.Bool( "i", false, "print input value in 1-liner mode")
+    d := flag.Bool( "d", false, "intaracitve mode")
     s := flag.Bool( "s", false, "server mode" )
-    p := flag.Int( "p", 80, "listen port in server mode" )
+    p := flag.Int( "p", 8080, "listen port in server mode" )
 
     flag.Parse()
 
@@ -44,7 +48,7 @@
         fmt.Fprint( os.Stderr, "> entai_app -i -l 20160731 20161224 30000\n\n" )
         fmt.Fprint( os.Stderr, "> entai_app -i -v -l 20160731 20161224 30000\n\n" )
         fmt.Fprint( os.Stderr, "server mode:\n" )
-        fmt.Fprint( os.Stderr, "> entai_app -s -p 8080\n" )
+        fmt.Fprint( os.Stderr, "> entai_app -s -p 3000\n" )
         os.Exit( 0 )
     }
 
@@ -60,6 +64,14 @@
         os.Exit( 0 )
     }
 
+    if *d {
+        PrintTile()
+        //layout := "20060102"
+        //for {
+        //}
+        os.Exit( 0 )
+    }
+
     if *l {
         layout := "20060102"
 
@@ -79,7 +91,7 @@
         }
 
         if *i {
-            fmt.Printf( "%v,%v,%d,", d.Format( layout ), p.Format( layout ), g )
+            fmt.Printf( "%v,%v,%d,", d.Format( layout ), p.Format( layout ), t )
         }
 
 		// MAIN
@@ -93,12 +105,37 @@
             fmt.Print( ",", detail )
         }
         fmt.Print( "\n" )
+        os.Exit( 0 )
+    }
+
+    if *b {
+        files := flag.Args()
+        if len( files ) == 0 {
+            fmt.Fprint( os.Stderr, "no input file.\n" )
+            os.Exit( 1 )
+        } else {
+            for _, file := range files {
+                f, err := os.Open( file ); if err != nil {
+                    fmt.Fprintf( os.Stderr, "cannot open file.[%v]\n", err )
+                    os.Exit( 1 )
+                }
+                input := bufio.NewScanner( f )
+                b := bufio.NewWriter( os.Stdout )
+                for input.Scan() {
+                    s := strings.Split( input.Text(), "," )
+                    fmt.Fprint( b, s[0] )
+                }
+                b.Flush()
+                f.Close()
+            }
+            os.Exit( 0 )
+        }
     }
 }
 
 func PrintTile() {
     fmt.Fprint( os.Stderr, "\n==================================================\n" )
-    fmt.Fprint( os.Stderr, "  Entai_app ver 0.1  ( 2016.09.29 ) - since 2016\n" )
+    fmt.Fprint( os.Stderr, "  Entai_app ver 0.2  ( 2016.10.09 ) - since 2016\n" )
     fmt.Fprint( os.Stderr, "==================================================\n\n" )
 }