tccli (empty) → 0.0.1
raw patch · 4 files changed
+76/−0 lines, 4 filesdep +basedep +bytestringdep +tokyocabinet-haskellsetup-changed
Dependencies added: base, bytestring, tokyocabinet-haskell, utf8-string
Files
- COPYING +13/−0
- Setup.hs +3/−0
- tccli.cabal +16/−0
- tchcli.hs +44/−0
+ COPYING view
@@ -0,0 +1,13 @@+Copyright (c) 2009, Voker57++All rights reserved.++Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:++Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.++Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.++The name of author may not be used to endorse or promote products derived from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ Setup.hs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runghc+import Distribution.Simple+main = defaultMain
+ tccli.cabal view
@@ -0,0 +1,16 @@+Name: tccli+Version: 0.0.1+Synopsis: TokyoCabinet CLI interface+Author: Voker57+Maintainer: voker57@gmail.com+Build-type: Simple+Cabal-version: >= 1.4+Stability: experimental+License: BSD3+License-file: COPYING+Category: Database+Description: Simple TokyoCabinet CLI interface+Homepage: http://bitcheese.net/wiki/code/tccli+Executable tchcli+ Main-is: tchcli.hs+ Build-Depends: base >= 4.0 && < 5.0, tokyocabinet-haskell, bytestring >= 0.9, utf8-string
+ tchcli.hs view
@@ -0,0 +1,44 @@+import qualified Data.ByteString.Lazy as BSL+import qualified Data.ByteString.Lazy.UTF8 as BUL+import Database.TokyoCabinet.HDB+import System.Environment (getArgs)++printUsage = do+ putStrLn "Simple TokyoCabinet hash storage interface."+ putStrLn "Usage: tchcli <db file> <action> <args>"+ putStrLn "Examples: tchcli mydb.tch get mykey # gets value of mykey and prints it to STDOUT"+ putStrLn " tchcli mydb.tch put mykey # stores data from STDIN as mykey in database"+ putStrLn " tchcli mydb.tch putcat mykey # appends data from STDIN to mykey in database"++performTricks dbname action arg = do+ case action of+ "get" -> do+ db <- new+ open db dbname [OCREAT, OREADER]+ result <- get db (BUL.fromString arg)+ maybe (putStr "") (BSL.putStr) result+ "put" -> do+ db <- new+ open db dbname [OCREAT, OWRITER]+ put db (BUL.fromString arg) =<< BSL.getContents+ return ()+ "putcat" -> do+ db <- new+ open db dbname [OCREAT, OWRITER]+ putcat db (BUL.fromString arg) =<< BSL.getContents+ return ()+ "num" -> do+ db <- new+ open db dbname [OCREAT, OREADER]+ print =<< rnum db+ otherwise -> printUsage++main = do+ args <- getArgs+ if (length args < 3) then+ printUsage+ else do+ let [dbname, action, arg] = args+ performTricks dbname action arg+ +