2016-06-09 2 views
1

clojure/tools.cli 및 lein bin을 사용하여 clojure 라이브러리의 명령 줄 버전을 생성하려고합니다. 스크립트를 실행할 때 출력이 stderr로 바뀌는 것을 제외하고는 정상적으로 작동합니다. 이 특정 라이브러리에는 몇 가지 기본 기능을 무시하는 함수가 있으므로 자연스럽게 클로저 코드가 컴파일 될 때 경고가 발생합니다. 나는 이것이 일반적으로 나쁜 생각이지만,이 경우에 신중히 고려한 후에 그것이 최선의 방법이라고 믿습니다. 스크립트를 실행할 때마다이 메시지가 나타나지 않게하려면 어떻게합니까?clojure 프로그램에서 stderr로 출력을 억제하는 방법

monger 문서에서 권장하는 종속성에 slf4j-nop을 추가하여 monger로부터 원하지 않는 메시지가 표시되지 않도록합니다.이 방법은 작동하지만 clojure 컴파일러의 경고에는 영향을 미치지 않습니다.

또한 여기에 설명 된대로 slf4j-log를 사용해 보았습니다. 성공한 경우는 suppress output from `clojure.tools.logging`입니다.

project.clj

(defproject image-search "0.1.0-SNAPSHOT" 
    :description "Search for images containing specific metadata" 
    :url "http://github.com/soulflyer/image-search" 
    :license {:name "Eclipse Public License" 
     :url "http://www.eclipse.org/legal/epl-v10.html"} 
    :dependencies [[org.clojure/clojure "1.7.0"] 
       [org.clojure/tools.cli "0.3.3"] 
       [org.slf4j/slf4j-nop "1.7.21"] 
       [image-lib "0.1.1-SNAPSHOT"]] 
    :main image-search.command-line 
    :bin {:name "image-search" 
     :bin-path "~/bin"}) 

및 command_line.clj : 나는 lein 빈을 실행

(ns image-search.command-line 
    (:require [image-search.core :refer [open all-images ifeq ifin ]] 
      [clojure.tools.cli :refer :all]) 
    (:gen-class)) 

(def cli-options 
    [["-c" "--count" "Counts the results"] 
    ["-D" "--database DATABASE" "specifies database to use" 
    :default "photos"] 
    ["-I" "--image-collection IMAGE-COLLECTION" "specifies the image collection" 
    :default "images"] 
    ["-K" "--keyword-collection KEYWORD-COLLECTION" "specifies the keyword collection" 
    :default "keywords"] 
    ["-h" "--help"] 
    ["-i" "--iso ISO" "Search on ISO value"] 
    ["-s" "--shutter SHUTTER-SPEED" "search on SHUTTER-SPEED"] 
    ["-f" "--aperture APERTURE" "search on APERTURE"] 
    ["-y" "--year YEAR" "search on YEAR"] 
    ["-m" "--month MONTH" "search on MONTH"] 
    ["-M" "--model MODEL" "search by camera model"] 
    ["-p" "--project PROJECT" "search photos in PROJECT"] 
    ["-k" "--keyword KEYWORD" "search for KEYWORD"]]) 

(defn print-count [pics] 
    (println (count pics))) 

(defn -main 
    "I don't do a whole lot ... yet." 
    [& args] 
    (let [{:keys [options arguments errors summary]} (parse-opts args cli-options) 
     output-function (if (:count options) print-count open)] 

    (-> all-images 
     (ifeq :ISO-Speed-Ratings (:iso options)) 
     (ifeq :Year    (:year options)) 
     (ifeq :Month    (:month options)) 
     (ifin :Project   (:project options)) 
     (ifeq :F-Number  (:aperture options)) 
     (ifin :Keywords  (:keyword options)) 
     (ifin :Model    (:model options)) 
     (output-function)))) 

, 다음이 생성하는 실행 파일을 실행하고 얻을 여기

코드의 일부입니다 다음과 같은 내용 :

(master) image-search: image-search -i 640 -c 
WARNING: or already refers to: #'clojure.core/or in namespace: image-search.core, being replaced by: #'image-search.core/or 
WARNING: and already refers to: #'clojure.core/and in namespace: image-search.core, being replaced by: #'image-search.core/and 

2 경고는 명령 줄 버전에서 사용하지 않는 기능을 나타냅니다. 나는 그들을 포함하지도 않는다. 그들은 내가 도서관을 요구할 때 언급 된 목록에 없습니다. 그러나 그들은 repl 또는 cider에서 사용할 때 라이브러리에서 중요합니다. 그래서 나는 정말로 그것들의 이름을 바꾸고 싶지 않습니다.

당신은 추가하여 경고를 제거 할 수 있습니다

답변

2

당신의 (ns image-search.core) 선언에 다음과 같은 : 당신은 여전히 ​​사용할 수 변경으로

(ns image-search.core 
    (:refer-clojure :exclude [or and]) 

원래 Clojure에서의 orand 완전히 그 자격으로 :없이

`clojure.core/or` 
`clojure.core/and` 

을 컴파일러를 변경하면 orand의 네임 스페이스 바인딩을 재정의한다는 사실이 기본적으로의 함수에 바인딩되어 있으므로 경고합니다및 clojure/and 바.

관련 문제