vigoo / clipp Goto Github PK
View Code? Open in Web Editor NEWCLI Parameter Parser library
License: Apache License 2.0
CLI Parameter Parser library
License: Apache License 2.0
Hi! I see that zio 2 support is on master. Can you make a release please?
Path
Suppose I want to define an application that takes parameters like this:
app --dir /data --in ./src/input --out ./out/result
where the meaning of -in
and -out
are file paths that are relative to --dir
.
I would like to define the parameters --in
and --out
dependent on the parameter --dir
so that I could have access to the value of the --dir
parameter in the custom parsers for --in
and --out
.
In this example, the custom parser for --in
would verify that the relative path, ./src/input
, exists in the directory specified by --dir
, ie., /data/src/input
.
Are there any impediments to cross-building and publishing scala3 binaries?
I would like to define a parameters class like this;
case class Parameters(x: List[String], y: String)
and use clipp to parse the command line arguments like this:
app -x v1 v2 v3 -y foo
or like this:
app -x v1 -x v2 -x v3 -y foo
This includes two things:
choice
for the known values)This is a great library for ZIO - Thank you! Can you bump to the latest ZIO version?
The doc for custom parsers requires implementing a type class:
trait ParameterParser[T] {
def parse(value: String): Either[String, T]
def default: T
}
For example, using the kebs tag library, I can define a tagged type for an existing executable file like this:
import io.github.vigoo.clipp.ParameterParser
import pl.iterators.kebs.tagged._
sealed trait ExecutableTag
implicit val executableFileParser: ParameterParser[Option[File] @@ ExecutableTag] =
new ParameterParser[Option[File] @@ ExecutableTag] {
override def parse(value: String): Either[String, Option[File] @@ ExecutableTag] = {
val f = new File(value)
val v0 = Right(Some(f).taggedWith[ExecutableTag])
val v1 = if (f.canExecute) v0 else Left(s"The path must be an executable file, got: $value")
val v2 = if (f.isFile) v1 else Left(s"The path must be a file, got: $value")
val v3 = if (f.isAbsolute) v2 else Left(s"The path must be absolute, got: $value")
v3
}
override def default: Option[File] @@ ExecutableTag = None.taggedWith[ExecutableTag]
}
Since it does not make sense to define a default file value, the custom parameter type is: Option[File] @@ ExecutableTag
.
However, when defining a custom parameters data structure, I would like to ensure we have an existing file; however, it is unclear how to turn the lack of a file into a parser error; e.g.:
case class Parameters(tool: File @@ ExecutableTag)
object Parameters {
val spec: Free[Parameter, Parameters] = for {
_ <- metadata(....)
otool <- namedParameter[Option[File] @@ ExecutableTag](
description = "an executable file",
placeholder = "tool",
shortName = 't',
longNames = "tool")
tool <- ??? // we would like to get otool if Some and produce an error if otool if None.
} yield Parameters(tool)
}
How could we solve this problem?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.