OSDN Git Service

commit
[blackquill/BlackQuill.git] / src / main / scala / BlackQuill.scala
1 package org.blackquill
2
3 // BlackQuill Copyright (C) 2013 set.minami<set,minami@gmail.com>
4 // Lisence MIT see also LISENCE.txt
5 // Main object and set Switches.
6
7 import scala.collection.JavaConversions._
8 import scala.util.matching._
9
10 object BlackQuill{
11   val VERSION = "0.1.0"
12   val lastDate = "May 14 2013"
13
14   val wiki = "https://github.com/setminami/BlackQuill/wiki/"
15   val syntax = "BlackQuill-Details-of-Syntax"
16   val philosophy = "BlackQuill-Philosophy"
17
18   val options = 
19     "--force|-f : Force conversion. BQ ignore timestamps of markdown files.\n" +
20     "--stdout|-s :BQ outputs document to STDOUT as HTML.\n" + 
21     "--enc shift-jis|euc-jp|UTF-8|ASCII default input enc is UTF-8\n" +
22     "- : BQ accept markdown document from STDIN\n"  +
23     "--output DIR|-o :BQ outputs HTML to under DIR\n" +
24     "--verbose|-v :output conversion processes verbosely \n" +
25     "--version :output version and so on.\n" + 
26     "--help|-h :output usage descriptions\n" +
27     "...and  Markdown file's suffix is .md|.markdown|.txt|.bq|.BlackQuill\n" +
28     "e.g., BlackQuill --force foo.md"
29
30
31   val description = "Welcome to BlackQuill.\n" +
32     "BQ switches=> \n" + options +
33     "Please see also... \n" +
34     wiki + syntax + "\n" +
35     wiki + philosophy + "\n" 
36
37   object Switches{
38     def setInputfile(input:String){inputFile = input}
39     def getInputfile{inputFile}
40
41     def setForce(b:Boolean){force = b}
42     def getForce{force}
43     def setStdout(b:Boolean){stdout = b}
44     def getStdout{stdout}
45     def setStdin(b:Boolean){stdin = b}
46     def getStdin{stdin}
47     def setOutput(b:Boolean,dir:String){output = b;dirName = dir}
48     def getOutput{output}
49     def getOutputDir{dirName}
50     def setVerbose(b:Boolean){verbose = b}
51     def getVerbose{verbose}
52     def setEncoding(b:Boolean,enc:String){encFlag=b;encode = enc}
53     def getEncoding{encode}
54
55     private
56     var inputFile = ""
57     var force = false
58
59     var stdout = false
60
61     var stdin = false
62
63     var output = false
64     var dirName = ""
65
66     var verbose = false
67     var encFlag = false
68     var encode = "UTF-8"
69
70   }
71
72   def main(args:Array[String]){
73
74     val f : Regex = """(.+)\s(.+)""".r 
75     val sufRegex = """(\.md$)|(\.markdown$)|(\.txt$)|(\.bq$)|(\.blackquill$)""".r
76
77     try{
78       args.foreach({s =>
79         println("=>" + s)
80         s match {
81           case "--force"|"-f" => Switches.setForce(true)
82           case "--stdout"|"-s" => Switches.setStdout(true)
83           case f("--enc",v) => Switches.setEncoding(true,v)
84           case f("--output",v) => Switches.setOutput(true,v)
85           case "--verbose"|"-v" => Switches.setVerbose(true)
86           case "--version" => println("BlackQuill Version" + VERSION + " updated at " + lastDate)
87           case "--help"|"-h" =>
88             println(description)
89           case _ => 
90             if(sufRegex.findFirstIn(s) != None){
91               Switches.setInputfile(s)
92             }else{
93               throw new RuntimeException
94             }
95         }
96       })
97     }catch{ case e:Exception => println("wrong switch is found see --help or Website\n" + wiki)}
98   }
99
100   
101 }
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116