Giter VIP home page Giter VIP logo

argbuilder's Introduction

argbuilder - command line arguments building DSL

The library provides a monadic DSL to build command line arguments. It is especially useful for building more specific DSLs.

For example, let's define something like Hadoop Streaming command line arguments DSL:

data Env = Env
    { envScriptPath :: FilePath
    , envResourcePath :: FilePath
    }

data HadoopArgState = HadoopArgState
    { stOutput :: Maybe FilePath
    }

type HadoopArgM w a = ArgBuilderM Env HadoopArgState w a

-- ... defining some combinators ...


-- Example function
exampleArgs :: Bool -> HadoopArgM Argument ()
exampleArgs noFooMode = do
  "-D" =:@ do arg ("stream.num.map.output.key.fields",    "4")
              arg ("mapred.text.key.partitioner.options", "-k2,4")
              arg ("stream.num.reduce.output.key.fields", "5")

  inputs ["s3://path/to/input"]
  output "s3://path/to/output"

  mapper "Map" $ do
    when noFooMode $ flag "--no-foo"
    (Equals, "--dictionary") =:: "file.txt"

  reducer "ReducerUsesFooBarBinary.sh" $ do
    flag "--enable-foo"
    (Sticky, "-a") =:@ do arg "Date"
                          arg "Time"
                          arg "Asset"

  cacheFile $ do
    script "FooBar"
    resource $ "directory/some-file.txt" `alias` "file.txt"

  cmdenv "BEGINDATE" "2013-01-01"
  cmdenv "ENDDATE"   "2013-01-01"

Outputs the following list of arguments

-D
stream.num.map.output.key.fields=4
-D
mapred.text.key.partitioner.options=-k2,4
-D
stream.num.reduce.output.key.fields=5
-input
s3://path/to/input
-output
s3://path/to/output
-mapper
/bin/Map --no-foo --dictionary=file.txt
-reducer
/bin/ReducerUsesFooBarBinary.sh --enable-foo -aDate -aTime -aAsset
-cacheFile
/bin/FooBar#FooBar
-cacheFile
/etc/directory/some-file.txt#file.txt
-cmdenv
BEGINDATE=2013-01-01
-cmdenv
ENDDATE=2013-01-01

argbuilder's People

Contributors

esmolanka avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.