update to basic-cli 0.12

This commit is contained in:
Anton-4 2024-07-10 20:07:03 +02:00
parent b65e65f0a4
commit 3a36d84c45
No known key found for this signature in database
GPG key ID: 0971D718C0A9B937
25 changed files with 47 additions and 142 deletions

View file

@ -256,7 +256,7 @@ mod tests {
use std::io::Write; use std::io::Write;
use tempfile::{tempdir, TempDir}; use tempfile::{tempdir, TempDir};
const FORMATTED_ROC: &str = r#"app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } const FORMATTED_ROC: &str = r#"app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Task import pf.Task
@ -264,7 +264,7 @@ import pf.Task
main = main =
Stdout.line! "I'm a Roc application!""#; Stdout.line! "I'm a Roc application!""#;
const UNFORMATTED_ROC: &str = r#"app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } const UNFORMATTED_ROC: &str = r#"app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout

View file

@ -1,66 +0,0 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" }
import pf.Stdout
import pf.Arg
import pf.Task exposing [Task]
main =
args = Arg.list!
parser =
divCmd =
Arg.succeed (\dividend -> \divisor -> Div (Num.toF64 dividend) (Num.toF64 divisor))
|> Arg.withParser
(
Arg.i64Option {
long: "dividend",
short: "n",
help: "the number to divide; corresponds to a numerator",
}
)
|> Arg.withParser
(
Arg.i64Option {
long: "divisor",
short: "d",
help: "the number to divide by; corresponds to a denominator",
}
)
|> Arg.subCommand "div"
logCmd =
Arg.succeed (\base -> \num -> Log (Num.toF64 base) (Num.toF64 num))
|> Arg.withParser
(
Arg.i64Option {
long: "base",
short: "b",
help: "base of the logarithm",
}
)
|> Arg.withParser
(
Arg.i64Option {
long: "num",
help: "the number to take the logarithm of",
}
)
|> Arg.subCommand "log"
Arg.choice [divCmd, logCmd]
|> Arg.program { name: "args-example", help: "A calculator example of the CLI platform argument parser" }
when Arg.parseFormatted parser args is
Ok cmd ->
runCmd cmd
|> Num.toStr
|> Stdout.line
Err helpMenuErr ->
Task.err (Exit 1 "unable to parse args: $(Inspect.toStr helpMenuErr)")
runCmd = \cmd ->
when cmd is
Div n d -> n / d
Log b n ->
# log_b(n) = log_x(n) / log_x(b) for all x
runCmd (Div (Num.log n) (Num.log b))

View file

@ -1,4 +1,4 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Task exposing [Task] import pf.Task exposing [Task]

View file

@ -1,4 +1,4 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdin import pf.Stdin
import pf.Stdout import pf.Stdout

View file

@ -1,4 +1,4 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdin import pf.Stdin
import pf.Stdout import pf.Stdout

View file

@ -1,4 +1,4 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Stderr import pf.Stderr

View file

@ -1,25 +1,26 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Task exposing [Task] import pf.Task exposing [Task]
import pf.File import pf.File
import pf.Path import pf.Path
import pf.Env import pf.Env
import pf.Dir
main : Task {} [Exit I32 Str]_ main : Task {} [Exit I32 Str]_
main = main =
path = Path.fromStr "out.txt" pathStr = "out.txt"
task = task =
cwd = Env.cwd! cwdPath = Env.cwd!
Stdout.line! "cwd: $(Path.display cwd)" cwdStr = Path.display cwdPath
dirEntries = Dir.list! cwd Stdout.line! "Current working directory: $(cwdStr)"
dirEntries = Path.listDir! cwdPath
contentsStr = Str.joinWith (List.map dirEntries Path.display) "\n " contentsStr = Str.joinWith (List.map dirEntries Path.display) "\n "
Stdout.line! "Directory contents:\n $(contentsStr)\n" Stdout.line! "Directory contents:\n $(contentsStr)\n"
Stdout.line! "Writing a string to out.txt" Stdout.line! "Writing a string to out.txt"
File.writeUtf8! path "a string!" File.writeUtf8! pathStr "a string!"
contents = File.readUtf8! path contents = File.readUtf8! pathStr
Stdout.line! "I read the file back. Its contents: \"$(contents)\"" Stdout.line! "I read the file back. Its contents: \"$(contents)\""
when Task.result! task is when Task.result! task is

View file

@ -1,4 +1,4 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdin import pf.Stdin
import pf.Stdout import pf.Stdout

View file

@ -1,4 +1,4 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Http import pf.Http
import pf.Task exposing [Task] import pf.Task exposing [Task]

View file

@ -1,10 +1,11 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import "ingested-file.roc" as license import "test-file.txt" as testFile
main = main =
license # Due to the functions we apply on testFile, it will be inferred as a List U8.
testFile
|> List.map Num.toU64 |> List.map Num.toU64
|> List.sum |> List.sum
|> Num.toStr |> Num.toStr

View file

@ -1,11 +1,11 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import "ingested-file.roc" as license : _ # A type hole can also be used here. import "test-file.txt" as testFile : _ # the _ is optional
main = main =
# Due to how license is used, it will be a List U8. # Due to the functions we apply on testFile, it will be inferred as a List U8.
license testFile
|> List.map Num.toU64 |> List.map Num.toU64
|> List.sum |> List.sum
|> Num.toStr |> Num.toStr

View file

@ -1,4 +1,4 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import "ingested-file.roc" as ownCode : Str import "ingested-file.roc" as ownCode : Str

View file

@ -1,8 +1,7 @@
app [main] { app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br", pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br",
} }
import pf.Arg
import pf.Stdout import pf.Stdout
import pf.Task exposing [Task] import pf.Task exposing [Task]

View file

@ -1,5 +1,5 @@
app [main] { app [main] {
cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br", cli: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br",
parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.5.2/9VrPjwfQQ1QeSL3CfmWr2Pr9DESdDIXy97pwpuq84Ck.tar.br", parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.5.2/9VrPjwfQQ1QeSL3CfmWr2Pr9DESdDIXy97pwpuq84Ck.tar.br",
} }

View file

@ -1,14 +1,14 @@
app [main] { app [main] {
pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br", pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br",
parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.5.2/9VrPjwfQQ1QeSL3CfmWr2Pr9DESdDIXy97pwpuq84Ck.tar.br", parser: "https://github.com/lukewilliamboswell/roc-parser/releases/download/0.5.2/9VrPjwfQQ1QeSL3CfmWr2Pr9DESdDIXy97pwpuq84Ck.tar.br",
} }
import pf.Stdout import pf.Stdout
import pf.Stderr import pf.Stderr
import pf.Task exposing [Task] import pf.Task exposing [Task]
import parser.Core exposing [Parser, map, keep] import parser.Core exposing [map, keep]
import parser.String exposing [strFromUtf8] import parser.String exposing [strFromUtf8]
import parser.CSV exposing [CSV] import parser.CSV
input : Str input : Str
input = "Airplane!,1980,\"Robert Hays,Julie Hagerty\"\r\nCaddyshack,1980,\"Chevy Chase,Rodney Dangerfield,Ted Knight,Michael O'Keefe,Bill Murray\"" input = "Airplane!,1980,\"Robert Hays,Julie Hagerty\"\r\nCaddyshack,1980,\"Chevy Chase,Rodney Dangerfield,Ted Knight,Michael O'Keefe,Bill Murray\""

View file

@ -0,0 +1 @@
Used by ingested-file-bytes.roc and ingested-file-bytes-no-ann.roc

View file

@ -79,6 +79,8 @@ mod cli_run {
#[derive(Debug, PartialEq, Eq)] #[derive(Debug, PartialEq, Eq)]
enum Arg<'a> { enum Arg<'a> {
ExamplePath(&'a str), ExamplePath(&'a str),
// allow because we may need PlainText in the future
#[allow(dead_code)]
PlainText(&'a str), PlainText(&'a str),
} }
@ -799,39 +801,6 @@ mod cli_run {
) )
} }
#[test]
#[ignore = "currently broken in basic-cli platform"]
#[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")]
#[serial(cli_platform)]
fn cli_args() {
test_roc_app(
"examples/cli",
"argsBROKEN.roc",
&[],
&[
Arg::PlainText("log"),
Arg::PlainText("-b"),
Arg::PlainText("3"),
Arg::PlainText("--num"),
Arg::PlainText("81"),
],
&[],
"4\n",
UseValgrind::No,
TestCliCommands::Run,
)
}
// TODO: remove in favor of cli_args once mono bugs are resolved in investigation
#[test]
#[cfg_attr(windows, ignore = "missing __udivdi3 and some other symbols")]
#[serial(cli_platform)]
fn cli_args_check() {
let path = file_path_from_root("crates/cli/tests/cli", "argsBROKEN.roc");
let out = run_roc([CMD_CHECK, path.to_str().unwrap()], &[], &[]);
assert!(out.status.success());
}
// TODO: write a new test once mono bugs are resolved in investigation // TODO: write a new test once mono bugs are resolved in investigation
#[test] #[test]
#[cfg(not(debug_assertions))] // https://github.com/roc-lang/roc/issues/4806 #[cfg(not(debug_assertions))] // https://github.com/roc-lang/roc/issues/4806
@ -1030,7 +999,7 @@ mod cli_run {
&[], &[],
&[], &[],
&[], &[],
"27101\n", "6239\n",
UseValgrind::No, UseValgrind::No,
TestCliCommands::Run, TestCliCommands::Run,
) )
@ -1045,7 +1014,7 @@ mod cli_run {
&[], &[],
&[], &[],
&[], &[],
"27101\n", "6239\n",
UseValgrind::No, UseValgrind::No,
TestCliCommands::Run, TestCliCommands::Run,
) )

View file

@ -1783,7 +1783,7 @@ fn roc_file_no_extension() {
indoc!( indoc!(
r#" r#"
app "helloWorld" app "helloWorld"
packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } packages { pf: "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
imports [pf.Stdout] imports [pf.Stdout]
provides [main] to pf provides [main] to pf

View file

@ -1,6 +1,6 @@
app [main] { app [main] {
pf: pf:
"https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br", "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br",
} }
main = main =

View file

@ -19,7 +19,7 @@ Full {
], ],
platform_marker: None, platform_marker: None,
package_name: @17-132 PackageName( package_name: @17-132 PackageName(
"https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br", "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br",
), ),
}, },
[ [

View file

@ -1,5 +1,5 @@
app [main] { pf: app [main] { pf:
"https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br"
} }
main = main =

View file

@ -1,4 +1,4 @@
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Task import pf.Task

View file

@ -1,7 +1,7 @@
# #
# Shows how Roc values can be logged # Shows how Roc values can be logged
# #
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Task import pf.Task

View file

@ -7,7 +7,7 @@ Something that sets Roc apart from other programming languages is its <span clas
Here is a Roc application that prints `"Hello, World!"` to the command line: Here is a Roc application that prints `"Hello, World!"` to the command line:
```roc ```roc
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Task import pf.Task

View file

@ -154,7 +154,7 @@ Let's move out of the REPL and create our first Roc application!
Make a file named `main.roc` and put this in it: Make a file named `main.roc` and put this in it:
```roc ```roc
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Task import pf.Task
@ -1454,7 +1454,7 @@ Besides being built into the compiler, the builtin modules are different from ot
Let's take a closer look at the part of `main.roc` above the `main` def: Let's take a closer look at the part of `main.roc` above the `main` def:
```roc ```roc
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
``` ```
@ -1572,7 +1572,7 @@ We'll use these four operations to learn about tasks.
Let's start with a basic "Hello World" program. Let's start with a basic "Hello World" program.
```roc ```roc
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
@ -1605,7 +1605,7 @@ Once this task runs, we'll end up with the [tag union](https://www.roc-lang.org/
Let's change `main` to read a line from `stdin`, and then print what we got: Let's change `main` to read a line from `stdin`, and then print what we got:
```roc ```roc
app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.10.0/vNe6s9hWzoTZtFmNkvEICPErI9ptji_ySjicO6CkucY.tar.br" } app [main] { pf: platform "https://github.com/roc-lang/basic-cli/releases/download/0.12.0/Lb8EgiejTUzbggO2HVVuPJFkwvvsfW6LojkLR20kTVE.tar.br" }
import pf.Stdout import pf.Stdout
import pf.Stdin import pf.Stdin