Browse Source

Command line interface was added (test12).

SakiKawasaki 5 years ago
parent
commit
3926b6f082
6 changed files with 88 additions and 2 deletions
  1. 10 0
      README.md
  2. 2 2
      badgemaker/badgemaker.nim
  3. 54 0
      badgemaker/badgemaker/CLI.nim
  4. 16 0
      tests/CLI.svg
  5. BIN
      tests/test12.exe
  6. 6 0
      tests/test12.nim

+ 10 - 0
README.md

@@ -4,6 +4,16 @@ The Nim badgemaker tool.
 
 ## Install
 -   via git: `nimble install https://github.com/Ethosa/badgemaker`
+-   via nimble: `nimble install badgemaker`
+
+
+## Now support
+-   Custom font (change size available).
+-   Custom icons.
+-   Custom colors (label, value, text).
+-   Custom badge size.
+-   Custom styles (flat, plastic, square, plastic square).
+-   CLI.
 
 
 ## Standart badge params

+ 2 - 2
badgemaker/badgemaker.nim

@@ -90,14 +90,14 @@ proc `$`*(badge: BadgeRef): string =
 
   main.add newXMLTree(
     "rect", [], {
-      "x": "0", "y": "0", "width": $(labelw - badge.font_size),
+      "x": "0", "y": "0", "width": $labelw,
       "height": $badge.height, "rx": radius, "ry": radius,
       "style": "fill:" & badge.label_color
     }.toXMLAttributes)
   main.add newXMLTree(
     "rect", [], {
       "x": $dif, "y": "0",
-      "width": $((badge.width - (badge.font_size/2).int) - (dif)),
+      "width": $((badge.width - (badge.font_size/2).int) - dif),
       "height": $badge.height,
       "rx": "0", "ry": "0", "style": "fill:" & badge.value_color
     }.toXMLAttributes)

+ 54 - 0
badgemaker/badgemaker/CLI.nim

@@ -0,0 +1,54 @@
+# author: Ethosa
+# Command Line Interface for badgemaker.
+import badgemaker
+import parseopt
+import strutils
+import json
+
+
+proc parseCommandLine*(args: seq[string]) =
+  ## Parses command-line arguments and work with them.
+  ##
+  ## Command line arguments example:
+  ##   yourfile --filename:CLI.svg --width:100
+  ##
+  ## ..code-block::Nim
+  ##   import badgemaker/CLI
+  ##   import os
+  ##   parseCommandLine commandLineParams()
+  let params = %*{
+    "filename": %"CLI.svg",
+    "width": %"120",
+    "height": %"20",
+    "label": %"",
+    "value": %"",
+    "label_color": %"#212121",
+    "label_text_color": %"#e0e0e0",
+    "value_color": %"#e0e0e0",
+    "value_text_color": %"#212121",
+    "image_path": %"",
+    "image_color": %"",
+    "font": %"DejaVu Sans,Verdana,Geneva,sans-serif",
+    "font_size": %"12",
+    "style": %"plastic"
+  }
+  var opts = initOptParser(args)
+  for kind, key, value in opts.getopt:
+    case kind
+    of cmdEnd: continue
+    of cmdArgument: continue
+    of cmdShortOption, cmdLongOption:
+      if value != "":
+        if params.hasKey(key):
+          params[key] = %value
+  var badge = newBadge(
+    label=params["label"].getStr, value=params["value"].getStr,
+    width=params["width"].getStr.parseInt, height=params["height"].getStr.parseInt,
+    label_color=params["label_color"].getStr, label_text_color=params["label_text_color"].getStr,
+    value_color=params["value_color"].getStr, value_text_color=params["value_text_color"].getStr,
+    style=params["style"].getStr
+  )
+  badge.setFont params["font"].getStr
+  badge.setFontSize params["font_size"].getStr.parseInt
+  badge.setIcon params["image_path"].getStr, params["image_color"].getStr
+  badge.write params["filename"].getStr

+ 16 - 0
tests/CLI.svg

@@ -0,0 +1,16 @@
+<svg width="120" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://www.w3.org/2000/svg" height="20">
+  <linearGradient x2="0" id="gradient" y2="100%">
+    <stop stop-color="#bbb" stop-opacity=".1" offset="0" />
+    <stop stop-opacity=".1" offset="1" />
+  </linearGradient>
+  <g mask="url(#gradient)">
+    <rect style="fill:#212121" width="0" y="0" x="0" rx="4" height="20" ry="4" />
+    <rect style="fill:#e0e0e0" width="122" y="0" x="-8" rx="0" height="20" ry="0" />
+    <rect style="fill:#e0e0e0" width="12" y="0" x="108" rx="4" height="20" ry="4" />
+    <path fill="url(#gradient)" d="M0 0h120v20H0z" />
+  </g>
+  <g font-size="12" fill="#212121" font-family="DejaVu Sans,Verdana,Geneva,sans-serif">
+    <text y="15.0" x="6" fill="#e0e0e0"></text>
+    <text y="15.0" x="-6" fill="#212121"></text>
+  </g>
+</svg>

BIN
tests/test12.exe


+ 6 - 0
tests/test12.nim

@@ -0,0 +1,6 @@
+# author: Ethosa
+# CLI test 1
+import badgemaker/CLI
+import os
+
+parseCommandLine commandLineParams()