// Copyright 2026 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
///|
/// Get the command line arguments passed to the program.
pub fn args() -> Array[String] {
get_cli_args_internal()
}
///|
/// Get the current time in milliseconds since the Unix epoch.
pub fn now() -> UInt64 {
now_internal()
}
///|
/// Get the current working directory. On some platforms, this may return `None` if the current directory cannot be determined.
pub fn current_dir() -> String? {
current_dir_internal()
}
///|
/// Get an environment variable by key. Returns `None` if the key does not exist.
pub fn get_env_var(key : String) -> String? {
get_env_var_internal(key)
}
///|
/// Get all environment variables.
pub fn get_env_vars() -> Map[String, String] {
get_env_vars_internal()
}
///|
/// Set an environment variable.
pub fn set_env_var(key : String, value : String) -> Unit {
set_env_var_internal(key, value)
}
///|
/// Unset an environment variable.
pub fn unset_env_var(key : String) -> Unit {
unset_env_var_internal(key)
}
///|
/// Get `n` random bytes from a platform entropy source.
/// Returns `Some(bytes)` when the platform can provide secure random bytes,
/// and `None` on targets/environments that do not support entropy.
pub fn rand(n : Int) -> Bytes? {
if n <= 0 {
let probe : FixedArray[Byte] = FixedArray::make(1, b'\x00')
return if rand_internal(probe) { Some(b"") } else { None }
}
let buf : FixedArray[Byte] = FixedArray::make(n, b'\x00')
if rand_internal(buf) {
Some(Bytes::from_array(buf))
} else {
None
}
}
///|
/// Currently `moon` does not support conditional import,
/// so native-only import will result in unused import warning on other targets.
/// Manually supress the unused warning here.
#cfg(not(target="native"))
#warnings("-unused_value")
fn unused_function() -> Unit {
ignore(@ref.Ref(42))
ignore(@utf8.encode(""))
}