# shell2batch
**Repository Path**: michaelcheuang/shell2batch
## Basic Information
- **Project Name**: shell2batch
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-05-28
- **Last Updated**: 2020-12-19
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# shell2batch
[](https://crates.io/crates/shell2batch) [](https://github.com/sagiegurari/shell2batch/actions) [](https://codecov.io/gh/sagiegurari/shell2batch)
[](https://github.com/sagiegurari/shell2batch/blob/master/LICENSE) [](https://libraries.io/cargo/shell2batch) [](https://docs.rs/crate/shell2batch/) [](https://crates.io/crates/shell2batch)
[](https://sagiegurari.github.io/cargo-make)
> Coverts simple basic shell scripts to windows batch scripts.
* [Overview](#overview)
* [Usage](#usage)
* [Installation](#installation)
* [API Documentation](https://sagiegurari.github.io/shell2batch/)
* [Contributing](.github/CONTRIBUTING.md)
* [Release History](CHANGELOG.md)
* [License](#license)
## 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](https://sagiegurari.github.io/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:
```rust
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:
```ini
[dependencies]
shell2batch = "^0.4.2"
```
## API Documentation
See full docs at: [API Docs](https://sagiegurari.github.io/shell2batch/)
## Contributing
See [contributing guide](.github/CONTRIBUTING.md)
## Release History
See [Changelog](CHANGELOG.md)
## License
Developed by Sagie Gur-Ari and licensed under the Apache 2 open source license.