Giter VIP home page Giter VIP logo

sheen's Introduction

Sheen

Package Version Hex Docs

gleam add sheen

Sheen is a library for creating command line argument parsers. It has a convenient and type safe API.

THE API IS CURRENTLY UNSTABLE. I'D ADVISE AGAINST DEPENDING ON THIS PACKAGE BEFORE THE RELEASE OF VERSION 1.0.0

import argv
import sheen
import sheen/flag
import sheen/arg
import sheen/named

type Mode {
  Sum
  Product
}

type Args {
  Args(verbosity: Int, numbers: List(Int), mode: Mode)
}

fn parser() -> sheen.Parser(Args) {
  // You are asserting that you've built the parser correctly
  // Otherwise you will receive informative errors
  let assert Ok(parser) =
    sheen.new()
    |> sheen.name("Number cruncher")
    |> sheen.version("0.1.0")
    |> sheen.authors(["Ellie"])
    |> sheen.build({
      use verbosity <-
        flag.new("verbose")
        |> flag.count()

      use mode <-
        named.new("mode")
        |> named.enum([#("sum", Sum), #("product", Product)])
        |> named.required()

      use numbers <-
        arg.new()
        |> arg.integer()
        |> arg.repeated()

      sheen.return({
        use verbosity <- verbosity
        use numbers <- numbers
        use mode <- mode
        sheen.valid(Args(verbosity, numbers, mode))
      })
    })
  parser
}

pub fn main() {
  let parse_result =
    parser()
    |> sheen.run(argv.load().arguments)
  case parse_result {
    Ok(args) -> {
      // Run you program with the parsed arguments
      todo
    }
    Error(errors) -> {
      // Sheen collects all errors and returns them as a list.
      // Later I will add a way to pretty print them, and then
      // show usage information.
      todo
    }
  }
}

Further documentation can be found at https://hexdocs.pm/sheen.

sheen's People

Contributors

ehllie avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  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.