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.
-- 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
>> 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
--- /dev/null
+{-# LANGUAGE OverloadedStrings #-}
+
+module Main where
+
+import AddProgram
+import Data.Text
+import Data.Text.ANSI
+
+main :: IO ()
+main = saveProgram
--- /dev/null
+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
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:
-- 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,
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