-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Start Haskell implementation, move Haskell code to sub-directory
- Loading branch information
Showing
21 changed files
with
312 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
/.stack-work | ||
/*.cabal | ||
/.nickel | ||
/cli-spec.json |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
# Haskell Template | ||
# Oclis Changelog | ||
|
||
- 2023-11-27 - 0.0.0.0 | ||
- Initial release | ||
- [TBD] - 0.1.0.0 | ||
- First implementation of code generation for Haskell and PureScript |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
/.stack-work | ||
/*.cabal | ||
/dist-newstyle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
{-# LANGUAGE OverloadedStrings #-} | ||
{-# LANGUAGE QuasiQuotes #-} | ||
|
||
module Main where | ||
|
||
import Protolude ( | ||
Bool (..), | ||
IO, | ||
Maybe (..), | ||
pure, | ||
putText, | ||
when, | ||
($), | ||
(&), | ||
(<>), | ||
) | ||
import Protolude qualified as P | ||
|
||
import Oclis as O | ||
import Oclis.App as OA | ||
import Oclis.Option as OO | ||
import Text.RawString.QQ (r) | ||
|
||
|
||
myCliApp :: OA.App | ||
myCliApp = | ||
OA.defaultApp | ||
{ name = "my-cli-app" | ||
, version = Just "1.0" | ||
, OA.description = | ||
Just | ||
[r| | ||
# My CLI App | ||
|
||
This is a CLI app that does something | ||
|] | ||
, options = | ||
[ OO.Option | ||
{ long = Just "verbose" | ||
, short = Nothing | ||
, OO.description = Just "Enable verbose output" | ||
, argument = ArgNone | ||
, defaultValue = P.undefined -- Boolean False | ||
, required = False | ||
} | ||
, OO.Option | ||
{ long = Just "log-file" | ||
, short = Just 'l' | ||
, OO.description = Just "Log file to write to" | ||
, argument = ArgOne "FILE" | ||
, defaultValue = P.undefined -- Boolean False | ||
, required = False | ||
} | ||
] | ||
, run = | ||
\opts _args -> do | ||
P.putText "Hello, world!" | ||
|
||
when (opts & O.hasFlag "verbose") $ do | ||
P.putText "Verbose output enabled" | ||
|
||
case opts & O.getOptionVal "log-file" of | ||
Nothing -> P.putText "No log file specified" | ||
Just file -> P.putText $ "Writing logs to " <> file | ||
, commands = [] | ||
} | ||
|
||
|
||
main :: IO () | ||
main = do | ||
putText "Test" | ||
-- TODO: execute myCliApp args | ||
pure () |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.PHONY: help | ||
help: makefile | ||
@tail -n +4 makefile | grep ".PHONY" | ||
|
||
|
||
.PHONY: test | ||
test: | ||
stack test | ||
|
||
|
||
.PHONY: build | ||
build: | ||
stack build | ||
|
||
|
||
.PHONY: install | ||
install: | ||
stack install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# Oclis for Haskell | ||
|
||
## Used Technologies | ||
|
||
- [Stack](https://docs.haskellstack.org/en/stable/README/) | ||
- [Fourmolu](https://fourmolu.github.io) | ||
- [Haskell Language Server ](https://github.com/haskell/haskell-language-server) | ||
- [Protolude](https://github.com/protolude/protolude) | ||
- [Hspec](https://hspec.github.io) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module Oclis ( | ||
module Oclis.App, | ||
module Oclis.Option, | ||
hasFlag, | ||
getOptionVal, | ||
) | ||
where | ||
|
||
import Protolude (Bool, Maybe, Text) | ||
import Protolude qualified as P | ||
|
||
import Oclis.App | ||
import Oclis.Option hiding (description) | ||
|
||
|
||
hasFlag :: Text -> [Option] -> Bool | ||
hasFlag = P.undefined | ||
|
||
|
||
getOptionVal :: Text -> [Option] -> Maybe Text | ||
getOptionVal = P.undefined |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Oclis.App where | ||
|
||
import GHC.Show (show) | ||
import Protolude (IO, Maybe (..), Show, Text, pure) | ||
|
||
import Oclis.Option (Option) | ||
|
||
|
||
data App = App | ||
{ name :: Text | ||
, version :: Maybe Text | ||
, description :: Maybe Text | ||
, options :: [Option] | ||
, run :: [Option] -> [Text] -> IO () | ||
, commands :: [App] | ||
} | ||
|
||
|
||
instance Show App where | ||
show _ = "<app>" | ||
|
||
|
||
defaultApp :: App | ||
defaultApp = | ||
App | ||
{ name = "oclis" | ||
, version = Nothing | ||
, description = Nothing | ||
, options = [] | ||
, run = \_ _ -> pure () | ||
, commands = [] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
module Oclis.Option ( | ||
Argument (..), | ||
Option (..), | ||
defaultOption, | ||
) where | ||
|
||
import Protolude (Bool (..), Char, Eq, Maybe (..), Show, Text) | ||
|
||
import Data.Aeson (Value) | ||
|
||
|
||
data Argument | ||
= ArgNone | ||
| ArgOne Text | ||
| ArgMany Text | ||
deriving (Show, Eq) | ||
|
||
|
||
data Option = Option | ||
{ long :: Maybe Text | ||
, short :: Maybe Char | ||
, description :: Maybe Text | ||
, argument :: Argument | ||
, required :: Bool | ||
, defaultValue :: Maybe Value | ||
} | ||
deriving (Show, Eq) | ||
|
||
|
||
defaultOption :: Option | ||
defaultOption = | ||
Option | ||
{ long = Nothing | ||
, short = Nothing | ||
, description = Nothing | ||
, argument = ArgNone | ||
, required = False | ||
, defaultValue = Nothing | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
resolver: lts-21.15 | ||
resolver: lts-22.8 | ||
packages: | ||
- "." | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{-# LANGUAGE OverloadedRecordDot #-} | ||
|
||
import Protolude (IO, ($)) | ||
import Test.Hspec (describe, hspec, it, shouldBe) | ||
|
||
import Oclis | ||
|
||
|
||
main :: IO () | ||
main = hspec $ do | ||
describe "Oclis" $ do | ||
it "has a default app" $ do | ||
defaultApp.name `shouldBe` "oclis" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,12 @@ | ||
.PHONY: test | ||
test: | ||
stack test | ||
.PHONY: help | ||
help: makefile | ||
@tail -n +4 makefile | grep ".PHONY" | ||
|
||
|
||
.PHONY: build | ||
build: | ||
stack build | ||
build: cli-spec.json | ||
|
||
|
||
.PHONY: install | ||
install: | ||
stack install | ||
cli-spec.json: oclis-contract.ncl oclis.ncl | ||
echo '(import "oclis-contract.ncl") & (import "oclis.ncl")' \ | ||
| nickel export --format json > $@ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Contract for Oclis specifcations | ||
{ | ||
name | ||
| String | ||
| doc "The name of the command", | ||
version | ||
| String, | ||
description | ||
| String | ||
| optional, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
name = "oclis", | ||
version = "0.1.0.0", | ||
description = m%" | ||
Generate a CLI parser and executor | ||
from a given `oclis.ncl` specification file. | ||
"%, | ||
run = "runApp" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,71 @@ | ||
# Haskell Template | ||
# Oclis | ||
|
||
Opinionated template for new Haskell projects. | ||
CLI (Command Line Interface) app builder | ||
based on a simple, obvious specification file. | ||
|
||
|
||
## Used Technologies | ||
## Motivation | ||
|
||
- [Stack](https://docs.haskellstack.org/en/stable/README/) | ||
- [Fourmolu](https://fourmolu.github.io) | ||
- [Haskell Language Server ](https://github.com/haskell/haskell-language-server) | ||
- [Protolude](https://github.com/protolude/protolude) | ||
Building a CLI application is a repetitive task. | ||
The same code is written over and over again. | ||
But fear not, Oclis is here to help you out! | ||
|
||
|
||
## Usage | ||
|
||
1. Clone this repository | ||
1. Rename the folder to your project name | ||
1. Replace all occurences of `haskell-template` with your project name | ||
1. Run `stack test` to build the project and run the tests | ||
1. Run `stack run` to run the project | ||
1. Run `stack install` to install the project (make it available in your PATH) | ||
1. Write a simple specification file. | ||
2. Run `oclis` to generate the CLI parsing code for the language of your choice. | ||
3. Define the handler functions for your commands. | ||
4. Done 🎉 | ||
|
||
|
||
## Related | ||
|
||
### Tools | ||
|
||
- [CLI Definition Language] - DSL for defining command line interfaces | ||
of C++ programs. | ||
- [Decli] - Declarative CLI tool builder. | ||
- [docopt] - Command-line interface description language. | ||
- [make-cli] - Declarative CLI framework for Node.js. | ||
|
||
[CLI Definition Language]: https://www.codesynthesis.com/projects/cli/ | ||
[Decli]: https://github.com/woile/decli | ||
[docopt]: http://docopt.org/ | ||
[make-cli]: https://github.com/dword-design/make-cli | ||
|
||
|
||
### Specifications | ||
|
||
- [clig.dev] - Command Line Interface Guidelines. | ||
- [GNU Table of Long Options][gtolo] | ||
- [Heroku CLI Style Guide][hcsg] | ||
- [OpenAutoComplete] - CLI autocomplete specification. | ||
- [POSIX Utility Conventions][puc] | ||
|
||
[clig.dev]: https://clig.dev | ||
[gtolo]: | ||
https://www.gnu.org/prep/standards/html_node/Option-Table.html#Option-Table | ||
[hcsg]: https://devcenter.heroku.com/articles/cli-style-guide | ||
[OpenAutoComplete]: https://github.com/openautocomplete/openautocomplete | ||
[puc]: https://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html | ||
|
||
|
||
### Generate GUIs From CLI | ||
|
||
- [Claui] - A GUI generator for [clap] using [egui]. | ||
- [Gooey] - Turn CLI programs into a full GUI application. | ||
- [Klask] - Automatically create GUI applications from [clap] apps. | ||
|
||
[clap]: https://github.com/clap-rs/clap | ||
[Claui]: https://github.com/grantshandy/claui | ||
[egui]: https://github.com/emilk/egui | ||
[Gooey]: https://github.com/chriskiehl/Gooey | ||
[Klask]: https://github.com/MichalGniadek/klask | ||
|
||
|
||
### Generate GUIs From Simple Code | ||
|
||
- [Streamlit] - Turns data scripts into shareable web apps. | ||
|
||
[Streamlit]: https://github.com/streamlit/streamlit |
Oops, something went wrong.