项目作者: sagiegurari

项目描述 :
Coverts simple basic shell scripts to windows batch scripts.
高级语言: Rust
项目地址: git://github.com/sagiegurari/shell2batch.git
创建时间: 2017-10-21T11:04:56Z
项目社区:https://github.com/sagiegurari/shell2batch

开源协议:Apache License 2.0

下载


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:

  1. fn main() {
  2. let script = shell2batch::convert(
  3. r#"
  4. set -x
  5. export FILE1=file1
  6. export FILE2=file2
  7. #this is some test code
  8. cp ${FILE1} $FILE2
  9. cp -r ${DIR1} $DIR2
  10. #another
  11. mv file2 file3
  12. export MY_DIR=directory
  13. #flags are supported
  14. rm -Rf ${MY_DIR}
  15. unset MY_DIR
  16. touch ./file3
  17. #provide custom windows command for specific shell command
  18. complex_bash_command --flag1 value2 # shell2batch: complex_windows_command /flag10 windows_value
  19. "#,
  20. );
  21. assert_eq!(
  22. script,
  23. r#"
  24. @echo on
  25. set FILE1=file1
  26. set FILE2=file2
  27. @REM this is some test code
  28. copy %FILE1% %FILE2%
  29. xcopy /E %DIR1% %DIR2%
  30. @REM another
  31. move file2 file3
  32. set MY_DIR=directory
  33. @REM flags are supported
  34. rmdir /S /Q %MY_DIR%
  35. set MY_DIR=
  36. copy /B .\file3+,, .\file3
  37. @REM provide custom windows command for specific shell command
  38. complex_windows_command /flag10 windows_value
  39. "#
  40. );
  41. println!("Script: {}", script);
  42. }

Installation

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

  1. [dependencies]
  2. 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.