Commit 2fd5a116 authored by Iustin Pop's avatar Iustin Pop

Move src/Ganeti/HTools/Program.hs to Program/Main.hs

This removes one more tab conflict; this is the last module in our
code where we have both x.hs and x/.

Furthermore, we collapse all actual code into the new Main.hs module,
leaving the htools.hs basically empty (will allow better testing in
the future).
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarGuido Trotter <ultrotter@google.com>
parent 208b02e3
......@@ -478,7 +478,6 @@ HS_LIB_SRCS = \
src/Ganeti/HTools/Loader.hs \
src/Ganeti/HTools/Node.hs \
src/Ganeti/HTools/PeerMap.hs \
src/Ganeti/HTools/Program.hs \
src/Ganeti/HTools/Program/Hail.hs \
src/Ganeti/HTools/Program/Hbal.hs \
src/Ganeti/HTools/Program/Hcheck.hs \
......@@ -486,6 +485,7 @@ HS_LIB_SRCS = \
src/Ganeti/HTools/Program/Hscan.hs \
src/Ganeti/HTools/Program/Hspace.hs \
src/Ganeti/HTools/Program/Hroller.hs \
src/Ganeti/HTools/Program/Main.hs \
src/Ganeti/HTools/Types.hs \
src/Ganeti/Hash.hs \
src/Ganeti/JQueue.hs \
......
......@@ -23,13 +23,20 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-}
module Ganeti.HTools.Program
module Ganeti.HTools.Program.Main
( personalities
, main
) where
import Ganeti.Common (PersonalityList)
import Ganeti.HTools.CLI (Options)
import Control.Exception
import Control.Monad (guard)
import Data.Char (toLower)
import System.Environment
import System.IO
import System.IO.Error (isDoesNotExistError)
import Ganeti.Common (formatCommands, PersonalityList)
import Ganeti.HTools.CLI (Options, parseOpts, genericOpts)
import qualified Ganeti.HTools.Program.Hail as Hail
import qualified Ganeti.HTools.Program.Hbal as Hbal
import qualified Ganeti.HTools.Program.Hcheck as Hcheck
......@@ -37,6 +44,7 @@ import qualified Ganeti.HTools.Program.Hscan as Hscan
import qualified Ganeti.HTools.Program.Hspace as Hspace
import qualified Ganeti.HTools.Program.Hinfo as Hinfo
import qualified Ganeti.HTools.Program.Hroller as Hroller
import Ganeti.Utils
-- | Supported binaries.
personalities :: PersonalityList Options
......@@ -68,3 +76,27 @@ personalities =
\ node reboots in a manner that doesn't conflict with the\
\ instances' topology"))
]
-- | Display usage and exit.
usage :: String -> IO ()
usage name = do
hPutStrLn stderr $ "Unrecognised personality '" ++ name ++ "'."
hPutStrLn stderr "This program must be installed under one of the following\
\ names:"
hPutStrLn stderr . unlines $ formatCommands personalities
exitErr "Please either rename/symlink the program or set\n\
\the environment variable HTOOLS to the desired role."
main :: IO ()
main = do
binary <- catchJust (guard . isDoesNotExistError)
(getEnv "HTOOLS") (const getProgName)
let name = map toLower binary
case name `lookup` personalities of
Nothing -> usage name
Just (fn, options, arguments, _) -> do
cmd_args <- getArgs
real_options <- options
(opts, args) <- parseOpts cmd_args name (real_options ++ genericOpts)
arguments
fn opts args
......@@ -25,38 +25,4 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
module Main (main) where
import Control.Exception
import Control.Monad (guard)
import Data.Char (toLower)
import System.Environment
import System.IO
import System.IO.Error (isDoesNotExistError)
import Ganeti.Common (formatCommands)
import Ganeti.HTools.CLI (parseOpts, genericOpts)
import Ganeti.HTools.Program (personalities)
import Ganeti.Utils
-- | Display usage and exit.
usage :: String -> IO ()
usage name = do
hPutStrLn stderr $ "Unrecognised personality '" ++ name ++ "'."
hPutStrLn stderr "This program must be installed under one of the following\
\ names:"
hPutStrLn stderr . unlines $ formatCommands personalities
exitErr "Please either rename/symlink the program or set\n\
\the environment variable HTOOLS to the desired role."
main :: IO ()
main = do
binary <- catchJust (guard . isDoesNotExistError)
(getEnv "HTOOLS") (const getProgName)
let name = map toLower binary
case name `lookup` personalities of
Nothing -> usage name
Just (fn, options, arguments, _) -> do
cmd_args <- getArgs
real_options <- options
(opts, args) <- parseOpts cmd_args name (real_options ++ genericOpts)
arguments
fn opts args
import Ganeti.HTools.Program.Main (main)
......@@ -41,7 +41,7 @@ import Test.Ganeti.Common
import Ganeti.BasicTypes
import Ganeti.HTools.CLI as CLI
import qualified Ganeti.HTools.Program as Program
import qualified Ganeti.HTools.Program.Main as Program
import qualified Ganeti.HTools.Types as Types
{-# ANN module "HLint: ignore Use camelCase" #-}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment