GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - rust-shell-script/rust-shell-script: Rustlike shell scripting language; Resilient & robust shell script, compiling to rust code/bash script

BranchesTags
Open more actions menu

Latest commit

 

History

14 Commits
14 Commits

Folders and files

NameName
Last commit message
Last commit date
examples
examples
 
 
runtime
runtime
 
 
src
src
 
 
.gitignore
.gitignore
 
 
Cargo.lock
Cargo.lock
 
 
Cargo.toml
Cargo.toml
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

rust-shell-script

Rustlike shell scripting language (WIP) -> use rust_cmd_lib instead.

Resilient & robust shell script, compiling to rust code/bash script

Build & Install

$ cargo build

Example

Source file

rust-shell-script$:~/rust-shell-script$ cat examples/hello.rss
cmd error_command() {
    do_something_failed
}

fun bad_greeting(name) {
    info "Running error_command ..."
    error_command
    output "hello, ${name}!"
}

fun good_greeting(name) {
    info "Running good_command ..."
    output "hello, ${name}!"
}

cmd main() {
    let bad_ans = $(bad_greeting "rust-shell-script")
    info "${bad_ans}"
    let good_ans = $(good_greeting "rust-shell-script")
    info "${good_ans}"
    return 0
}

Compiling to bash

compiling

rust-shell-script:~/rust-shell-script$ target/debug/rust-shell-script -t bash examples/hello.rss 
Generating bash script to examples/hello.sh ...

passing shellcheck

rust-shell-script:~/rust-shell-script$ shellcheck examples/hello.sh 
rust-shell-script:~/rust-shell-script$ echo $?
0

generated bash script

#!/bin/bash
#
# Generated by rust-shell-script
#
. "${RUNTIME:-.}/cmd_lib.sh"

error_command() {
    do_something_failed
}

function bad_greeting() {
    local name="$1"

    info "Running error_command ..."
    error_command
    output "hello, ${name}!"
}

function good_greeting() {
    local name="$1"

    info "Running good_command ..."
    output "hello, ${name}!"
}

main() {
    local bad_ans
    bad_ans=$(_call bad_greeting "rust-shell-script")
    info "${bad_ans}"
    local good_ans
    good_ans=$(_call good_greeting "rust-shell-script")
    info "${good_ans}"
    return 0
}

main "$@"

running script

All command errors will be captured automatically, even within bash function:

rust-shell-script:~/rust-shell-script/examples$ ./hello.sh 
Running error_command ...
/bin/bash: line 219: do_something_failed: command not found
FATAL: Running command (bad_ans=$(_call bad_greeting "rust-shell-script")) near script hello.sh:main():1 failed (ret=127)

Compiling to rust

compiling

tao@sophia:~/rust-shell-script$ target/debug/rust-shell-script -t rust examples/hello.rss 
Generating rust code to examples/hello.rs ...

generated rust code

// Generated by rust-shell-script
mod cmd_lib;
use crate::cmd_lib::{CmdResult, FunResult};

fn error_command() -> CmdResult {
    run_cmd!("do_something_failed")
}

fn bad_greeting(name: &str) -> FunResult {
    info!("Running error_command ...");
    error_command()?;
    output!("hello, {}!", name)
}

fn good_greeting(name: &str) -> FunResult {
    info!("Running good_command ...");
    output!("hello, {}!", name)
}

fn main() -> CmdResult {
    let bad_ans = bad_greeting("rust-shell-script")?;;
    info!("{}", bad_ans);
    let good_ans = good_greeting("rust-shell-script")?;;
    info!("{}", good_ans);
    return Ok(())
}

running rust code

rust-shell-script:~/rust-shell-script/examples$ rustc hello.rs
rust-shell-script:~/rust-shell-script/examples$ ./hello
Running error_command ...
Running ["do_something_failed"] ...
Error: Os { code: 2, kind: NotFound, message: "No such file or directory" }

About

Rustlike shell scripting language; Resilient & robust shell script, compiling to rust code/bash script

Topics

command-linerustshell-script

Resources

Readme
Apache-2.0 license
Activity

Stars

59 stars

Watchers

2 watching

Forks

1 fork
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.