Open Mte90 opened 2 weeks ago
cd
could (and probably should) be added as a bulit in command to amber, like echo
@b1ek all the non-failable GNU commands that are parto of POSIX should be built-in.
@b1ek all the non-failable GNU commands that are parto of POSIX should be built-in.
and most of these
Actually... perhaps built-ins could be failable as well:
mv "path/to/file.txt" "other/path/to/file.txt" failed {
echo "Couldn't move the file"
}
Let's do a list of commands that need a native support and what needs a function. Maybe we can support them natively and create functions like I did that improve the usage like a normal scripting language.
This function should have the following changes
pub fun make_executable(path: Text): Null {
if file_exist(origin) {
unsafe $chmod +x "{path}"$
return true
}
echo "The file {$path} doesn't exist!"
return false
}
To
pub fun make_executable(path: Text): Bool {
if file_exist(path) {
unsafe $chmod +x "{path}"$
return true
}
echo "The file {path} doesn't exist!"
return false
}
So I have to removed the non-failable commands from this PR.
About make_symbolic_link
I think that is better to rename it as create_symbolic_link
to keep the consistency.
Probably is missing a function to extract compressed files, download files and to search inside file content. I will work on those the next days.
I did some changes and added the download
command but I left a note for that.
every stdlib command should be covered by a test. the tests are in
src/tests/stdlib.rs
I never developed with Rust but I guess that is enough to generate the bash and check that is always the same right? Maybe this can be simplified instead of editing a rust file maybe a pure text file is more simplier?
I added also is_root
and is_command
and improved the download function.
@Mte90 if you want to write a standard function to download file, then maybe write one that detects available solution to download it like curl
, wget
, python
and then use the strategy to do it:
if {
not has_failed("curl") {
// ... run curl command
}
not has_failed("wget") {
// ... run wget command
}
not has_failed("python") {
// ... run python command (and detect python version)
}
not has_failed("wget") {
I think that is better a command that check if exist instead to run it to see what is the error.
In this way we can avoid issues more easily, that is why I added the is_command
function.
I think that is better a command that check if exist instead to run it to see what is the error. In this way we can avoid issues more easily, that is way I added the
is_command
function.
Sure! I just wanted to share an example of potential implementation
So I think that another round of review for the function so I can try to do the unit tests :-)
I did the various tests, I have to fix the download
one that returns:
thread 'tests::stdlib::download' panicked at src/tests/stdlib.rs:510:5:
assertion `left == right` failed
left: ""
right: "yes"
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
If you have suggestions they are accepted :-)
Fixed also the last test :-)
There are some conflicts with cargo.lock/toml
There are some conflicts with cargo.lock/toml
ftfy <3
So I added 3 new commands:
write
that can write or append contentget_env_var
that echo the variable and in case doesn't exist read the variable from the .env
fileload_env_file
export a .env
file variablesI am fighting with the compilation as we need $(echo "${!var}")
to read the variable exported otherwise doesn't work and I am trying to understand how to generate that line in this way.
So right now 2 tests fails.
So I added more commands:
move
a wrapper aroundmv
change_dir
a wrapper aroundcd
but in this way it is generated acd
command fine for shellcheck https://github.com/Ph0enixKM/Amber/issues/72make_symbolic_link
a wrapper aroundln -s
create_dir
a wrapper aroundmkdir -p
make_executable
a wrapper aroundchmod +x
switch_user_permission
a wrapper aroundchown -R
delete
a wrapper aroundrm -fr
In many of those cases there is a check if the file/folder exist, in case return a different boolean value and print the error. In 2 cases we need the
OR
condition so we can check if it is file and a folder.