Skip to content

Commit 56986f4

Browse files
authored
feat: support get cli args & env var (#73)
* split into internal/ffi * feat: support get cli args & env var * get env args in Map[String, String] * moon fmt * bump version * moon info
1 parent d12cee1 commit 56986f4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+458
-219
lines changed

.github/workflows/check.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
- main
77
pull_request:
88

9+
env:
10+
# just for testing env var
11+
MOON_TEST: "yes"
12+
913
jobs:
1014
build:
1115
strategy:

benchmark/benchmark.mbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
pub fn Task::new(name : String, f : () -> Unit, ~count : Int = 10) -> Task {
15+
pub fn Task::new(name : String, f : () -> Unit, count~ : Int = 10) -> Task {
1616
{ name, f, count }
1717
}
1818

benchmark/benchmark.mbti

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@ impl Criterion {
1212

1313
type Task
1414
impl Task {
15-
new(String, () -> Unit, ~count : Int = ..) -> Self
15+
new(String, () -> Unit, count~ : Int = ..) -> Self
1616
run(Self) -> TaskResult
1717
}
1818

1919
pub(readonly) struct TaskResult {
20-
pub(readonly) task : Task
21-
pub(readonly) average : Double
22-
pub(readonly) max : Double
23-
pub(readonly) min : Double
20+
task : Task
21+
average : Double
22+
max : Double
23+
min : Double
2424
}
2525
impl TaskResult {
2626
output(Self, Logger) -> Unit

crypto/chacha.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ pub fn chacha8(
295295
key : FixedArray[UInt],
296296
counter : UInt,
297297
block : Bytes,
298-
~nonce : UInt = 0
298+
nonce~ : UInt = 0
299299
) -> Bytes!Error {
300300
if key.length() != 8 {
301301
fail!("Invalid key length -- key must be 8 32-bit unsigned integers")
@@ -313,7 +313,7 @@ pub fn chacha12(
313313
key : FixedArray[UInt],
314314
counter : UInt,
315315
block : Bytes,
316-
~nonce : UInt = 0
316+
nonce~ : UInt = 0
317317
) -> Bytes!Error {
318318
if key.length() != 8 {
319319
fail!("Invalid key length -- key must be 8 32-bit unsigned integers")
@@ -331,7 +331,7 @@ pub fn chacha20(
331331
key : FixedArray[UInt],
332332
counter : UInt,
333333
block : Bytes,
334-
~nonce : UInt = 0
334+
nonce~ : UInt = 0
335335
) -> Bytes!Error {
336336
if key.length() != 8 {
337337
fail!("Invalid key length -- key must be 8 32-bit unsigned integers")

crypto/crypto.mbti

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ package moonbitlang/x/crypto
33
// Values
44
fn bytes_to_hex_string(Bytes) -> String
55

6-
fn chacha12(FixedArray[UInt], UInt, Bytes, ~nonce : UInt = ..) -> Bytes!
6+
fn chacha12(FixedArray[UInt], UInt, Bytes, nonce~ : UInt = ..) -> Bytes!
77

8-
fn chacha20(FixedArray[UInt], UInt, Bytes, ~nonce : UInt = ..) -> Bytes!
8+
fn chacha20(FixedArray[UInt], UInt, Bytes, nonce~ : UInt = ..) -> Bytes!
99

10-
fn chacha8(FixedArray[UInt], UInt, Bytes, ~nonce : UInt = ..) -> Bytes!
10+
fn chacha8(FixedArray[UInt], UInt, Bytes, nonce~ : UInt = ..) -> Bytes!
1111

1212
fn md5(Bytes) -> Bytes
1313

@@ -46,7 +46,7 @@ impl SM3Context {
4646
type Sha256Context
4747
impl Sha256Context {
4848
finalize(Self) -> Bytes
49-
new(~reg : FixedArray[UInt] = ..) -> Self
49+
new(reg~ : FixedArray[UInt] = ..) -> Self
5050
update(Self, Bytes) -> Unit
5151
update_from_iter(Self, Iter[Byte]) -> Unit
5252
}

crypto/sha256.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ struct Sha256Context {
2222
/// Instantiate a Sha256 context
2323
/// `reg` is the initial hash value. Defaults to Sha256's.
2424
pub fn Sha256Context::new(
25-
~reg : FixedArray[UInt] = [
25+
reg~ : FixedArray[UInt] = [
2626
0x6a09e667, 0xbb67ae85, 0x3c6ef372, 0xa54ff53a, 0x510e527f, 0x9b05688c, 0x1f83d9ab,
2727
0x5be0cd19,
2828
]
@@ -71,7 +71,7 @@ fn pad(self : Sha256Context) -> Bytes {
7171
fn transform(
7272
self : Sha256Context,
7373
data : Bytes,
74-
~offset : Int = 0
74+
offset~ : Int = 0
7575
) -> FixedArray[UInt] {
7676
let w = FixedArray::make(64, 0U)
7777
let mut a = self.reg[0]
@@ -161,7 +161,7 @@ pub fn update(self : Sha256Context, data : Bytes) -> Unit {
161161

162162
fn sha256_compute(
163163
self : Sha256Context,
164-
~data : Iter[Byte] = Iter::empty()
164+
data~ : Iter[Byte] = Iter::empty()
165165
) -> FixedArray[UInt] {
166166
self.update_from_iter(data)
167167
let msg = self.pad()

crypto/sm3.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ fn pad(self : SM3Context) -> Bytes {
108108
fn transform(
109109
self : SM3Context,
110110
data : Bytes,
111-
~offset : Int = 0
111+
offset~ : Int = 0
112112
) -> FixedArray[UInt] {
113113
let w_0 = FixedArray::make(68, 0U)
114114
let w_1 = FixedArray::make(64, 0U)
@@ -222,7 +222,7 @@ pub fn update(self : SM3Context, data : Bytes) -> Unit {
222222

223223
fn sm3_compute(
224224
self : SM3Context,
225-
~data : Iter[Byte] = Iter::empty()
225+
data~ : Iter[Byte] = Iter::empty()
226226
) -> FixedArray[UInt] {
227227
self.update_from_iter(data)
228228
let msg = self.pad()

crypto/utils.mbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ fn uint32(x : Byte) -> UInt {
5454
/// convert 4 bytes a byte sequence to a UInt in little endian
5555
/// - `x` : A byte sequence consisting of 4 or more bytes
5656
/// - `i` : An offset. e.g. i = 4 will convert `x[4~7]` to a UInt.
57-
fn u8_to_u32le(x : Bytes, ~i : Int = 0) -> UInt {
57+
fn u8_to_u32le(x : Bytes, i~ : Int = 0) -> UInt {
5858
uint32(x[i]) |
5959
(uint32(x[i + 1]) << 8) |
6060
(uint32(x[i + 2]) << 16) |
@@ -81,7 +81,7 @@ fn u8_to_u32le(x : Bytes, ~i : Int = 0) -> UInt {
8181
// )
8282
// }
8383

84-
fn bytes_u8_to_u32be(x : Bytes, ~i : Int = 0) -> UInt {
84+
fn bytes_u8_to_u32be(x : Bytes, i~ : Int = 0) -> UInt {
8585
(uint32(x[i]) << 24) |
8686
(uint32(x[i + 1]) << 16) |
8787
(uint32(x[i + 2]) << 8) |

fs/fs.mbt

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
pub type! IOError {
15+
pub(all) type! IOError {
1616
NotFound(String)
1717
}
1818

@@ -31,7 +31,7 @@ fn IOError::to_string(self : IOError) -> String {
3131
/// # Parameters
3232
/// - `path`: A `String` representing the file path.
3333
/// - `content`: A `String` containing the content to be written to the file.
34-
pub fn write_string_to_file(~path : String, ~content : String) -> Unit {
34+
pub fn write_string_to_file(path~ : String, content~ : String) -> Unit {
3535
@ffi.write_string_to_file(path, content)
3636
}
3737

@@ -41,7 +41,7 @@ pub fn write_string_to_file(~path : String, ~content : String) -> Unit {
4141
///
4242
/// - `path` : The path to the file where the bytes will be written.
4343
/// - `content` : An array of bytes to be written to the file.
44-
pub fn write_bytes_to_file(~path : String, ~content : Bytes) -> Unit {
44+
pub fn write_bytes_to_file(path~ : String, content~ : Bytes) -> Unit {
4545
@ffi.write_bytes_to_file(path, content)
4646
}
4747

@@ -52,7 +52,7 @@ pub fn write_bytes_to_file(~path : String, ~content : Bytes) -> Unit {
5252
///
5353
/// # Returns
5454
/// A boolean indicating whether the path exists.
55-
pub fn path_exists(~path : String) -> Bool {
55+
pub fn path_exists(path~ : String) -> Bool {
5656
@ffi.path_exists(path)
5757
}
5858

@@ -63,8 +63,8 @@ pub fn path_exists(~path : String) -> Bool {
6363
///
6464
/// # Returns
6565
/// A `String` containing the file contents if the file exists, otherwise raises an error.
66-
pub fn read_file_to_string(~path : String) -> String! {
67-
guard path_exists(~path) else { raise IOError::NotFound(path) }
66+
pub fn read_file_to_string(path~ : String) -> String! {
67+
guard path_exists(path~) else { raise IOError::NotFound(path) }
6868
@ffi.read_file_to_string(path)
6969
}
7070

@@ -78,8 +78,8 @@ pub fn read_file_to_string(~path : String) -> String! {
7878
/// # Returns
7979
///
8080
/// - An array of bytes representing the content of the file.
81-
pub fn read_file_to_bytes(~path : String) -> Bytes! {
82-
guard path_exists(~path) else { raise IOError::NotFound(path) }
81+
pub fn read_file_to_bytes(path~ : String) -> Bytes! {
82+
guard path_exists(path~) else { raise IOError::NotFound(path) }
8383
@ffi.read_file_to_bytes(path)
8484
}
8585

@@ -92,8 +92,8 @@ pub fn read_file_to_bytes(~path : String) -> Bytes! {
9292
/// # Returns
9393
///
9494
/// - An array of strings representing the file name and directory name in the directory.
95-
pub fn read_dir(~path : String) -> Array[String]! {
96-
guard path_exists(~path) else { raise IOError::NotFound(path) }
95+
pub fn read_dir(path~ : String) -> Array[String]! {
96+
guard path_exists(path~) else { raise IOError::NotFound(path) }
9797
@ffi.read_dir(path)
9898
}
9999

@@ -103,7 +103,7 @@ pub fn read_dir(~path : String) -> Array[String]! {
103103
/// # Parameters
104104
///
105105
/// - `path` : The path where the directory should be created.
106-
pub fn create_dir(~path : String) -> Unit {
106+
pub fn create_dir(path~ : String) -> Unit {
107107
@ffi.create_dir(path)
108108
}
109109

@@ -116,8 +116,8 @@ pub fn create_dir(~path : String) -> Unit {
116116
/// # Returns
117117
///
118118
/// - `Bool` : `true` if the path is a directory, `false` otherwise.
119-
pub fn is_dir(~path : String) -> Bool! {
120-
guard path_exists(~path) else { raise IOError::NotFound(path) }
119+
pub fn is_dir(path~ : String) -> Bool! {
120+
guard path_exists(path~) else { raise IOError::NotFound(path) }
121121
@ffi.is_dir(path)
122122
}
123123

@@ -130,8 +130,8 @@ pub fn is_dir(~path : String) -> Bool! {
130130
/// # Returns
131131
///
132132
/// - `Bool` : `true` if the path points to a file, `false` otherwise.
133-
pub fn is_file(~path : String) -> Bool! {
134-
guard path_exists(~path) else { raise IOError::NotFound(path) }
133+
pub fn is_file(path~ : String) -> Bool! {
134+
guard path_exists(path~) else { raise IOError::NotFound(path) }
135135
@ffi.is_file(path)
136136
}
137137

@@ -140,8 +140,8 @@ pub fn is_file(~path : String) -> Bool! {
140140
/// # Parameters
141141
///
142142
/// - `path` : The string path to the directory that needs to be removed.
143-
pub fn remove_dir(~path : String) -> Unit! {
144-
guard path_exists(~path) else { raise IOError::NotFound(path) }
143+
pub fn remove_dir(path~ : String) -> Unit! {
144+
guard path_exists(path~) else { raise IOError::NotFound(path) }
145145
@ffi.remove_dir(path)
146146
}
147147

@@ -150,7 +150,7 @@ pub fn remove_dir(~path : String) -> Unit! {
150150
/// # Parameters
151151
///
152152
/// - `path` : The path to the file that needs to be removed.
153-
pub fn remove_file(~path : String) -> Unit! {
154-
guard path_exists(~path) else { raise IOError::NotFound(path) }
153+
pub fn remove_file(path~ : String) -> Unit! {
154+
guard path_exists(path~) else { raise IOError::NotFound(path) }
155155
@ffi.remove_file(path)
156156
}

fs/fs.mbti

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,30 @@
11
package moonbitlang/x/fs
22

33
// Values
4-
fn create_dir(~path : String) -> Unit
4+
fn create_dir(path~ : String) -> Unit
55

6-
fn is_dir(~path : String) -> Bool!
6+
fn is_dir(path~ : String) -> Bool!
77

8-
fn is_file(~path : String) -> Bool!
8+
fn is_file(path~ : String) -> Bool!
99

10-
fn path_exists(~path : String) -> Bool
10+
fn path_exists(path~ : String) -> Bool
1111

12-
fn read_dir(~path : String) -> Array[String]!
12+
fn read_dir(path~ : String) -> Array[String]!
1313

14-
fn read_file_to_bytes(~path : String) -> Bytes!
14+
fn read_file_to_bytes(path~ : String) -> Bytes!
1515

16-
fn read_file_to_string(~path : String) -> String!
16+
fn read_file_to_string(path~ : String) -> String!
1717

18-
fn remove_dir(~path : String) -> Unit!
18+
fn remove_dir(path~ : String) -> Unit!
1919

20-
fn remove_file(~path : String) -> Unit!
20+
fn remove_file(path~ : String) -> Unit!
2121

22-
fn write_bytes_to_file(~path : String, ~content : Bytes) -> Unit
22+
fn write_bytes_to_file(path~ : String, content~ : Bytes) -> Unit
2323

24-
fn write_string_to_file(~path : String, ~content : String) -> Unit
24+
fn write_string_to_file(path~ : String, content~ : String) -> Unit
2525

2626
// Types and methods
27-
pub type! IOError {
27+
pub(all) type! IOError {
2828
NotFound(String)
2929
}
3030
impl Show for IOError

0 commit comments

Comments
 (0)