module Music.Theory.Db.Cli where
import qualified Music.Theory.Db.Csv as Csv
import qualified Music.Theory.Db.Common as Common
import qualified Music.Theory.Db.Plain as Plain
db_load_ty :: String -> FilePath -> IO (Common.Db String String)
db_load_ty :: String -> String -> IO (Db String String)
db_load_ty String
ty String
fn =
case String
ty of
String
"plain" -> forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (forall a b. (a -> b) -> [a] -> [b]
map forall k v. Record k [v] -> Record k v
Common.record_uncollate) (Sep -> String -> IO [Record]
Plain.db_load_utf8 Sep
Plain.sep_plain String
fn)
String
"csv" -> String -> IO (Db String String)
Csv.db_load_utf8 String
fn
String
_ -> forall a. HasCallStack => String -> a
error String
"db_load_ty"
db_store_ty :: String -> FilePath -> Common.Db String String -> IO ()
db_store_ty :: String -> String -> Db String String -> IO ()
db_store_ty String
ty String
fn =
case String
ty of
String
"plain" -> Sep -> String -> [Record] -> IO ()
Plain.db_store_utf8 Sep
Plain.sep_plain String
fn forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map forall k v. Eq k => Record k v -> Record k [v]
Common.record_collate
String
"csv" -> String -> Db String String -> IO ()
Csv.db_store_utf8 String
fn
String
_ -> forall a. HasCallStack => String -> a
error String
"db_store_ty"
convert :: (String,String) -> (FilePath,FilePath) -> IO ()
convert :: (String, String) -> (String, String) -> IO ()
convert (String
input_ty,String
output_ty) (String
input_fn,String
output_fn) = do
Db String String
db <- String -> String -> IO (Db String String)
db_load_ty String
input_ty String
input_fn
String -> String -> Db String String -> IO ()
db_store_ty String
output_ty String
output_fn Db String String
db
stat :: String -> FilePath -> IO ()
stat :: String -> String -> IO ()
stat String
ty String
fn = do
Db String String
db <- String -> String -> IO (Db String String)
db_load_ty String
ty String
fn
let ks :: [String]
ks = forall k v. Ord k => Db k v -> [k]
Common.db_key_set Db String String
db
forall a. Show a => a -> IO ()
print (String
"#-records",forall (t :: * -> *) a. Foldable t => t a -> Int
length Db String String
db)
forall a. Show a => a -> IO ()
print (String
"#-keys",forall (t :: * -> *) a. Foldable t => t a -> Int
length [String]
ks)
forall a. Show a => a -> IO ()
print (String
"key-set",[String] -> String
unwords [String]
ks)
help :: [String]
help :: [String]
help =
[String
"convert input-type output-type input-file output-file"
,String
"stat type file-name"
,String
""
,String
" type = csv | plain"]
db_cli :: [String] -> IO ()
db_cli :: [String] -> IO ()
db_cli [String]
arg = do
case [String]
arg of
[String
"convert",String
i_ty,String
o_ty,String
i_fn,String
o_fn] -> (String, String) -> (String, String) -> IO ()
convert (String
i_ty,String
o_ty) (String
i_fn,String
o_fn)
[String
"stat",String
ty,String
fn] -> String -> String -> IO ()
stat String
ty String
fn
[String]
_ -> String -> IO ()
putStrLn ([String] -> String
unlines [String]
help)