40 releases

0.4.5 Nov 1, 2022
0.4.4 Feb 6, 2022
0.4.3 Nov 19, 2021
0.4.2 Sep 28, 2019
0.1.6 Nov 3, 2017

#228 in Text processing

Download history 6092/week @ 2024-07-21 7598/week @ 2024-07-28 6624/week @ 2024-08-04 6045/week @ 2024-08-11 6387/week @ 2024-08-18 6529/week @ 2024-08-25 6047/week @ 2024-09-01 5992/week @ 2024-09-08 5167/week @ 2024-09-15 6229/week @ 2024-09-22 7724/week @ 2024-09-29 6930/week @ 2024-10-06 5556/week @ 2024-10-13 6692/week @ 2024-10-20 5692/week @ 2024-10-27 6319/week @ 2024-11-03

24,834 downloads per month
Used in 12 crates (via cargo-make)

Apache-2.0

1MB
853 lines

Contains (WOFF font, 400KB) docs/api/NanumBarunGothic.ttf.woff2, (WOFF font, 135KB) docs/api/FiraSans-Medium.woff2, (WOFF font, 130KB) docs/api/FiraSans-Regular.woff2, (WOFF font, 82KB) docs/api/SourceSerif4-Bold.ttf.woff2, (WOFF font, 77KB) docs/api/SourceSerif4-Regular.ttf.woff2, (WOFF font, 45KB) docs/api/SourceCodePro-It.ttf.woff2 and 3 more.

shell2batch

crates.io CI codecov
license Libraries.io for GitHub Documentation downloads
Built with cargo-make

Coverts simple basic shell scripts to windows batch scripts.

Overview

While it is not really possible to take every shell script and automatically convert it to a windows batch file, this library provides a way to convert simple basic shell commands to windows batch commands.
The original goal of this library is to provide users of cargo-make a way to write simple tasks with shell scripts without duplicating their code for each platform.

It is possible to provide custom conversion hints by using the # shell2batch: prefix (see below example).

Usage

Simply include the library and invoke the convert function as follows:

fn main() {
    let script = shell2batch::convert(
        r#"
        set -x

        export FILE1=file1
        export FILE2=file2

        #this is some test code
        cp ${FILE1} $FILE2
        cp -r ${DIR1} $DIR2

        #another
        mv file2 file3

        export MY_DIR=directory

        #flags are supported
        rm -Rf ${MY_DIR}

        unset MY_DIR

        touch ./file3

        #provide custom windows command for specific shell command
        complex_bash_command --flag1 value2 # shell2batch: complex_windows_command /flag10 windows_value
        "#,
    );

    assert_eq!(
        script,
        r#"
@echo on

set FILE1=file1
set FILE2=file2

@REM this is some test code
copy %FILE1% %FILE2%
xcopy /E %DIR1% %DIR2%

@REM another
move file2 file3

set MY_DIR=directory

@REM flags are supported
rmdir /S /Q %MY_DIR%

set MY_DIR=

copy /B .\file3+,, .\file3

@REM provide custom windows command for specific shell command
complex_windows_command /flag10 windows_value
"#
    );

    println!("Script: {}", script);
}

Installation

In order to use this library, just add it as a dependency:

[dependencies]
shell2batch = "^0.4.5"

API Documentation

See full docs at: API Docs

Contributing

See contributing guide

Release History

See Changelog

License

Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.

Dependencies

~2–3MB
~54K SLoC