-
-
Notifications
You must be signed in to change notification settings - Fork 366
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make use of MainArgs in example/basic/ (#2409)
We don't need to use it in all the examples, but I added it to a few. That means that someone following the examples will at least get some hints about how to do command line argument parsing, which is a common requirement when writing small CLI tools and utilities. Not strictly Mill/build-config related, but definitely handy for what we expect people to want to do with Mill
- Loading branch information
Showing
11 changed files
with
90 additions
and
40 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
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,8 +1,12 @@ | ||
package foo | ||
import scalatags.Text.all._ | ||
import mainargs.{main, ParserForMethods} | ||
object Foo { | ||
val value = h1("hello") | ||
def main(args: Array[String]): Unit = { | ||
println("Foo.value: " + Foo.value) | ||
@main | ||
def main(text: String) = { | ||
val value = h1(text) | ||
println(value) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |
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 |
---|---|---|
@@ -1,10 +1,14 @@ | ||
package foo | ||
import scalatags.Text.all._ | ||
import mainargs.{main, ParserForMethods} | ||
object Foo { | ||
val value = h1("hello") | ||
def main(args: Array[String]): Unit = { | ||
println("Foo.value: " + Foo.value) | ||
@main | ||
def main(text: String): Unit = { | ||
val value = h1(text) | ||
println("value: " + value) | ||
println("MyDeps.value: " + MyDeps.value) | ||
println("my.line.count: " + sys.props("my.line.count")) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |
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,9 +1,12 @@ | ||
package bar | ||
import scalatags.Text.all._ | ||
import mainargs.{main, ParserForMethods} | ||
object Bar { | ||
val value = p("world") | ||
|
||
def main(args: Array[String]): Unit = { | ||
println("Bar.value: " + bar.Bar.value) | ||
@main | ||
def main(text: String): Unit = { | ||
val value = p("world") | ||
println("Bar.value: " + value) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |
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 |
---|---|---|
@@ -1,10 +1,15 @@ | ||
package foo | ||
import scalatags.Text.all._ | ||
import mainargs.{main, ParserForMethods, arg} | ||
object Foo { | ||
val value = h1("hello") | ||
|
||
def main(args: Array[String]): Unit = { | ||
@main | ||
def main(@arg(name = "foo-text") fooText: String, | ||
@arg(name = "bar-text") barText: String): Unit = { | ||
println("Foo.value: " + Foo.value) | ||
println("Bar.value: " + bar.Bar.value) | ||
bar.Bar.main(barText) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |
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 |
---|---|---|
@@ -1,11 +1,19 @@ | ||
package qux | ||
import scalatags.Text.all._ | ||
import mainargs.{main, ParserForMethods, arg} | ||
object Qux { | ||
val value = p("today") | ||
|
||
def main(args: Array[String]): Unit = { | ||
println("Foo.value: " + foo.Foo.value) | ||
println("Bar.value: " + bar.Bar.value) | ||
println("Qux.value: " + qux.Qux.value) | ||
|
||
@main | ||
def main(@arg(name="foo-text") fooText: String, | ||
@arg(name="bar-text") barText: String, | ||
@arg(name="qux-text") quxText: String): Unit = { | ||
foo.Foo.main(fooText) | ||
bar.Bar.main(barText) | ||
|
||
val value = p(quxText) | ||
println("Qux.value: " + value) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |
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,5 +1,13 @@ | ||
package bar | ||
import scalatags.Text.all._ | ||
import mainargs.{main, ParserForMethods} | ||
object Bar { | ||
val value = p("world") | ||
|
||
@main | ||
def main(text: String): Unit = { | ||
val value = p(text) | ||
println("Bar.value: " + value) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |
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,10 +1,12 @@ | ||
package foo | ||
import scalatags.Text.all._ | ||
import mainargs.{main, ParserForMethods} | ||
object Foo { | ||
val value = h1("hello") | ||
|
||
def main(args: Array[String]): Unit = { | ||
println("Foo.value: " + Foo.value) | ||
println("Bar.value: " + bar.Bar.value) | ||
@main | ||
def main(text: String): Unit = { | ||
val value = h1(text) | ||
println("Foo.value: " + value) | ||
} | ||
|
||
def main(args: Array[String]): Unit = ParserForMethods(this).runOrExit(args) | ||
} |