 (defn pkg-to-relpath [path]
   (string/replace path #"^_/" ""))
 
-(defn package-name [name] (-> name (string/split #"\.") last))
-(defn package-camel [name] (-> name package-name string/capitalize))
-(defn package-path [base name] (str (pkg-to-relpath base) "/cci/" (string/replace name "." "/")))
+(defn- package-name [name] (-> name (string/split #"\.") last))
+(defn- package-camel [name] (-> name package-name string/capitalize))
+(defn- package-path [base name] (str (pkg-to-relpath base) "/cci/" (string/replace name "." "/")))
 
 ;;------------------------------------------------------------------
 ;; return a string with composite GOPATH elements, separated by ":"

;; write golang source to the filesystem, using gofmt to clean
;; up the generated code
;;-----------------------------------------------------------------
(defn emit-golang [outputfile content]
  (util/truncate-file outputfile content)
  (gofmt "-w" (.getCanonicalPath outputfile)))

;;-----------------------------------------------------------------
;; emit-stub
;;-----------------------------------------------------------------
(defn emit-stub [base name functions template srcdir filename]
  (let [[_ interface] (buildinterface base name functions)
        content (render-golang template [["base" base]["intf" interface]])
        output (io/file srcdir (package-path base name) filename)]

    (emit-golang output content)))

(defn emit-server-stub [base name functions srcdir]
  (emit-stub base name functions "server" srcdir "server-stub.go"))

;;-----------------------------------------------------------------
;; emit-proto
;;-----------------------------------------------------------------
(defn emit-proto [base srcdir [name ast :as interface]]
  (let [outputdir (io/file srcdir (package-path base name))
        output (io/file outputdir "interface.proto")]


    ;; execute the protoc compiler to generate golang
    (protoc-cmd outputdir output)))

;;-----------------------------------------------------------------
;; compile-metadata
;;-----------------------------------------------------------------
(def metadata-name "org.hyperledger.chaintool.meta")
(defn- compile-metadata []
  (let [data (->> (str "metadata/" metadata-name ".cci") io/resource slurp)]
    (intf/compileintf {:path metadata-name :data data})))

;;-----------------------------------------------------------------
;; compile interfaces
;;-----------------------------------------------------------------
(defn- compile-interfaces [ipath config]
  (let [interfaces (intf/compile ipath config)
        metadata (compile-metadata)]
    (assoc interfaces metadata-name metadata)))
