]> glassweightruler.freedombox.rocks Git - xdg-ninja.git/commitdiff
Restructure haskell code
authorb3nj4m1n <b3nj4m1n@gmx.net>
Fri, 20 May 2022 19:05:02 +0000 (21:05 +0200)
committerb3nj4m1n <b3nj4m1n@gmx.net>
Fri, 20 May 2022 19:09:04 +0000 (21:09 +0200)
README.md
lib/AddProgram.hs [moved from app/add-program.hs with 98% similarity]
src/add-program.hs [new file with mode: 0644]
src/xdgnj.hs [new file with mode: 0644]
xdgnj.cabal [moved from add-program.cabal with 60% similarity]

index 7204c1d1efcf2839dba4972a169f343df932b49f..3834647a03274eb8953d788042158bec5f156b84 100644 (file)
--- a/README.md
+++ b/README.md
@@ -47,13 +47,9 @@ You need _haskell_ and _cabal_ installed. (To be clear, this is just for a tool
 
 Run the following command:
 ```sh
-cabal build
+cabal run xdgnj add
 ```
 
-You should now have a binary which you can run. You'll find it in somewhere in _dist-newstyle/build_, for example in _dist-newstyle/build/x86_64-linux/ghc-9.0.2/add-program-0.1.0.0/x/add-program/build/add-program/add-program_.
-
-Execute this binary in this directory. It will guide you through the process.
-
 ### Manually
 
 We're going to use _git_ as an example.
similarity index 98%
rename from app/add-program.hs
rename to lib/AddProgram.hs
index a1446a3eb3ac4bb73576aca6c690669d88a0766f..77272eedeb1daf27047e765e883128ca45caf3ba 100644 (file)
@@ -3,6 +3,8 @@
 
 -- I do not know haskell, this code is probably shit
 
+module AddProgram where
+
 import           Data.Aeson
 import           Data.Aeson.Encode.Pretty
 import           Data.Aeson.Types
@@ -147,8 +149,8 @@ getProgram = do
            >> getFiles []
   return Program {name = T.pack name, files = files}
 
-main :: IO ()
-main = do
+saveProgram :: IO ()
+saveProgram = do
   program <- getProgram
   do_save <- promptBool (green "Save? (y/n) ") (red "Please provide a valid answer.") ""
   if do_save
diff --git a/src/add-program.hs b/src/add-program.hs
new file mode 100644 (file)
index 0000000..61e767a
--- /dev/null
@@ -0,0 +1,10 @@
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import           AddProgram
+import           Data.Text
+import           Data.Text.ANSI
+
+main :: IO ()
+main = saveProgram
diff --git a/src/xdgnj.hs b/src/xdgnj.hs
new file mode 100644 (file)
index 0000000..d2566c3
--- /dev/null
@@ -0,0 +1,41 @@
+module Main where
+
+import           AddProgram
+import           Data.Semigroup      ((<>))
+import           Options.Applicative
+
+data Args = AddProgram
+    | EditProgram String
+    | PreviewProgram String
+    | LintProgram String
+    | Lint
+    deriving Show
+
+editProgram :: Parser Args
+editProgram = EditProgram <$> argument str (metavar "PROGRAM")
+
+previewProgram :: Parser Args
+previewProgram = PreviewProgram <$> argument str (metavar "PROGRAM")
+
+lintProgram :: Parser Args
+lintProgram = LintProgram <$> argument str (metavar "PROGRAM")
+
+argsParser :: Parser Args
+argsParser = subparser
+        (command "add" (info (pure AddProgram) (progDesc "Add program"))
+      <> command "edit" (info editProgram (progDesc "Edit program config"))
+      <> command "prev" (info previewProgram (progDesc "Preview program config"))
+      <> command "lintp" (info lintProgram (progDesc "Lint program config"))
+      <> command "lint" (info (pure Lint) (progDesc "Lint all program configs")))
+
+args :: ParserInfo Args
+args = info (argsParser <**> helper)
+    ( fullDesc
+    <> progDesc "xdg-ninja utilities")
+
+main :: IO ()
+main = do
+    args <- execParser args
+    case args of
+        AddProgram -> saveProgram
+        _          -> print args
similarity index 60%
rename from add-program.cabal
rename to xdgnj.cabal
index aa5a1d4636a3e80ff6b28dc0840fe555989372cd..939dfa4f7074be5d5dc0afaa15baa5fda28f42eb 100644 (file)
@@ -1,6 +1,6 @@
 cabal-version:      2.4
-name:               add-program
-version:            0.1.0.0
+name:               xdg-ninja
+version:            0.2.0.0
 
 -- A short (one-line) description of the package.
 -- synopsis:
@@ -20,14 +20,7 @@ maintainer:         b3nj4m1n@gmx.net
 -- copyright:
 -- category:
 
-executable add-program
-    main-is:          add-program.hs
-
-    -- Modules included in this executable, other than Main.
-    -- other-modules:
-
-    -- LANGUAGE extensions used by modules in this package.
-    -- other-extensions:
+library
     build-depends:
         base ^>=4.15.1.0,
         process ^>=1.6.13.2,
@@ -40,6 +33,26 @@ executable add-program
         text-ansi ^>=0.1.1,
         extra ^>=1.7.10,
         aeson-pretty ^>=0.8.9,
-    hs-source-dirs:   app
+    hs-source-dirs:   lib
+    default-language: Haskell2010
+    exposed-modules: AddProgram
+
+executable add-program
+    main-is:          add-program.hs
+    build-depends:
+        base ^>=4.15.1.0,
+        text ^>=1.2.5.0,
+        text-ansi ^>=0.1.1,
+        xdg-ninja,
+    hs-source-dirs:   src
+    default-language: Haskell2010
+
+executable xdgnj
+    main-is:          xdgnj.hs
+    build-depends:
+        base ^>=4.15.1.0,
+        optparse-applicative ^>=0.17.0.0,
+        xdg-ninja,
+    hs-source-dirs:   src
     default-language: Haskell2010