-- Copyright: 2004-2012 Dino Morelli -- License: BSD3 (see LICENSE) -- Author: Dino Morelli module Opts ( Options (..) , parseOpts, usageText ) where import System.Console.GetOpt data Options = Options { optNoAction :: Bool , optQuiet :: Bool , optMove :: Bool , optNoDirs :: Bool , optHelp :: Bool } defaultOptions :: Options defaultOptions = Options { optNoAction = False , optQuiet = False , optMove = False , optNoDirs = False , optHelp = False } options :: [OptDescr (Options -> Options)] options = [ Option ['n'] ["no-action"] (NoArg (\opts -> opts { optNoAction = True } )) "Display what would be done, but do nothing" , Option ['q'] ["quiet"] (NoArg (\opts -> opts { optQuiet = True } )) "Suppress normal output of what's being done" , Option [] ["move"] (NoArg (\opts -> opts { optMove = True } )) "Move the files, don't just hard-link to the new locations" , Option ['D'] ["no-dirs"] (NoArg (\opts -> opts { optNoDirs = True } )) "No subdirectory hierarchy. Just do PARENTDIR/artist-title.ext" , Option ['h'] ["help"] (NoArg (\opts -> opts { optHelp = True } )) "This help text" ] parseOpts :: [String] -> IO (Options, [String]) parseOpts argv = case getOpt Permute options argv of (o,n,[] ) -> return (foldl (flip id) defaultOptions o, n) (_,_,errs) -> ioError $ userError (concat errs ++ usageText) usageText :: String usageText = (usageInfo header options) ++ "\n" ++ footer where header = init $ unlines [ "Usage: music-rename [OPTIONS] PARENTDIR FILES" , "Rename and move music files based on tag data" , "" , "Options:" ] footer = init $ unlines [ "This software is for renaming and storing your music files. It will extract artist, album and title info from the tag data in the music file and use that to build a meaningful new path for the file." , "" , "You get a subdirectory hierarchy consisting of directories for the artist (prefixed with PARENTDIR), then subdirs within those for the album. These album dirs contain the music files, renamed as artist-title.ext" , "" , "The PARENTDIR is the one given on the command-line to this utility, and probably represents the top-level of where you're storing music." , "" , "Note that the default behavior of this software is to create hard links to the new paths and leave the original links as they were. You can use the --move switch to blow away the original location, leaving only the new." , "" , "Version 1.4 Dino Morelli " ]