   (let [sets (:set m [])]
     (assoc m :set (into sets [v]))))
 
-(defn- parse-get [x]
+(defn- parse-f [x]
+  (if-not (contains? formats x) (fail (msgs :bad-format)))
+  x)
+
+(defn- parse-g [x]
   (string/split x #":" 2))
 
-(defn- parse-set [x]
+(defn- parse-s [x]
   (let [[nml+key val] (string/split x #"=" 2)
-        [nml key] (parse-get nml+key)]
+        [nml key] (parse-g nml+key)]
     [nml key val]))
 
 (def cliopts
-  [["-c" "--create"    "Create new namelist"                                                                ]
-   ["-g" "--get n:k"   "Get value of key 'k' in namelist 'n'"         :assoc-fn assoc-g :parse-fn parse-get ]
-   ["-h" "--help"      "Show usage information"                                                             ]
-   ["-i" "--in file"   "Input file (default: stdin)"                  :assoc-fn assoc-i                     ]
-   ["-n" "--no-prefix" "Report values without 'namelist:key=' prefix"                                       ]
-   ["-o" "--out file"  "Output file (default: stdout)"                :assoc-fn assoc-o                     ]
-   ["-s" "--set n:k=v" "Set value of key 'k' in namelist 'n' to 'v'"  :assoc-fn assoc-s :parse-fn parse-set ]
-   ["-v" "--version"   "Show version information"                                                           ]])
-
-;; formatting
-
-(defn- fmt-bash [m fname]
-  (let [ms  (sort m)
-        eq #(string/replace % "\"" "\\\"")
-        f0  (fn [[dataref values]]
-              (let [v (eq values)]
-                (str "'" dataref "') echo \"" v "\";;")))
-        f1  (fn [[name nvseq]]
-              (let [x (strmap f0 nvseq)]
-                (str "'" name "') case \"$2\" in " x "*) echo '';;esac;;" )))]
-    (str fname "(){ case \"$1\" in " (strmap f1 ms) "*) echo '';;esac; }\n")))
-
-(defn- fmt-namelist [m]
-  (let [f0 (fn [[dataref values]]
-             (str "  " dataref "=" values "\n"))
-        f1 (fn [[name nvseq]]
-             (str "&" name "\n" (strmap f0 (sort nvseq)) "/\n"))]
-    (strmap f1 (sort m))))
+  [["-c" "--create"     "Create new namelist"                                                              ]
+   ["-f" "--format fmt" "Output in the specified format (see below)"   :assoc-fn assoc-f :parse-fn parse-f ]
+   ["-g" "--get n:k"    "Get value of key 'k' in namelist 'n'"         :assoc-fn assoc-g :parse-fn parse-g ]
+   ["-h" "--help"       "Show usage information"                                                           ]
+   ["-i" "--in file"    "Input file (default: stdin)"                  :assoc-fn assoc-i                   ]
+   ["-n" "--no-prefix"  "Report values without 'namelist:key=' prefix"                                     ]
+   ["-o" "--out file"   "Output file (default: stdout)"                :assoc-fn assoc-o                   ]
+   ["-s" "--set n:k=v"  "Set value of key 'k' in namelist 'n' to 'v'"  :assoc-fn assoc-s :parse-fn parse-s ]
+   ["-v" "--version"    "Show version information"                                                         ]])
 
 ;; main
 
 (defn -main [& args]
   (alter-var-root #'*read-eval* (constantly false))
   (let [{:keys [options arguments summary]} (cli/parse-opts args cliopts)
-        fmt  fmt-namelist
         gets (:get options)
         sets (:set options)
         in   (or (:in  options) *in* )

  (apply str (map f coll)))

(defn- usage [summary]
  (doseq [x [""
             "Usage: nml [options]"
             ""
             "Options:"
             ""
             summary
             ""]]
    (println x))
  (System/exit 0))

;; nml private defns


  (let [tree  (nml-parse s :s)
        child :nvseq
        f     (fn [& v] (into [child] (nml-uniq v)))]
    (insta/transform {child f} tree)))

(defn- nml-uniq [values]
  (loop [head (first values) tail (rest values) tree []]
