Giter Site home page Giter Site logo

batchlib's Introduction

Batchlib

Collections of reusable functions/snippets for Batch Script.

These functions can be used by simply copy, paste it and CALL the function. Concept of the script have been refined over the years to allow easier development in Batch Script.

Features

  • Easy to use, suitable for beginners
  • Powerful, suitable for hardcore batch script users
  • Does not use global variables (otherwise specified in documentation)
  • Extensive documentation and demo
  • Functions have unittest and demo so functionality can be tested before use
  • Library dependency management for scripts

Getting Started

For first time use, run batchlib once to add dependencies automatically (batchlib also have dependencies!) and test the libraries to make sure it works. Another way to test it is by running these commands:

rem Test the Batchlib core
cmd /c batchlib.bat -c :tests

rem Test all library functions
cmd /c batchlib.bat test

A good way to get stated with batchlib is to explore the features and libraries first. After you are somehow familiar with them, use a Template For New Scripts, read the documentations inside, and try to make something out of it.

Template For New Scripts

To take full advantage of batchlib, there are some structures to follow. Use the template script template.bat as your starting point. It has all the recommended structures to work flawlessly with batchlib. There are guides inside to help you get started.

Minified Batchlib

Minified Batchlib is a stripped down and packed version of Batchlib.

The differences are:

  • All library functions (only the function) are compiled into the file.
  • No library docs, demo, or tests included.
  • Command line interface instead of menu interface.

To generate it, type:

cmd /c batchlib.bat template minified > batchlib-min.bat

Dependency Management

Batchlib have an automated way of adding libraries into a script. Use the Template For New Scripts and specify the dependencies in this section of the script:

:lib.dependencies
set "%~1install_requires=<your_dependencies_here>"
exit /b 0

And run:

# Add dependencies to file
cmd /c batchlib.bat build your_script_name.bat

# Or build with backup
cmd /c batchlib.bat build your_script_name.bat backup_name.bat

And batchlib will magically add the libraries into your script! Backup file can be specified if necessary. When you have changed the dependency list, you can run the same code again to update the libraries.

Call As External Library

It is possible to call batchlib as an external program. However, some functions will only work when it is copy-pasted (embedded) into the script.

These functions usually have note that says any of these:

- Function MUST be embedded into the script to work correctly
- Function SHOULD be embedded into the script

These are the recommended ways to do this (depending on use case):

rem 1. Use macro
set batchlib="C:\absolute\path\to\batchlib-min.bat" -c %=END=%
call %batchlib%:input_yesno -m "Sleep? [y/n] "

rem 2. Add to PATH
set "path=C:\absolute\path\to;%PATH%"
call batchlib-min -c :input_yesno -m "Midnight snacks? [y/n] "

At method #1, the %=END=% is used to prevent accidental truncation of trailing space.

Adding Your Own Functions To Library

You can use the template for new library as the starting point. Copying the library template and rename it:

copy lib\new_lib_template.bat lib\your_library_name.bat

This template contains all the structures you need for your function to work correctly with Batchlib. There are documentations inside to help you.

Unit Testing Your Script

There are 2 unit testing frameworks: unittest() and quicktest().

  • Use unittest() when more features are needed (supports test suite, experimental TAP output).
  • Use quicktest() when testing a small script.

Both frameworks have the same syntax so compatibility is not a problem.

batchlib's People

Stargazers

 avatar  avatar

Watchers

 avatar

batchlib's Issues

Would you consider releasing under Public Domain?

Usually, you'd use something like this by copying and paste little snippets into your own code. But MIT requires you to include the copyright notice with every use, which would mean you have to be tracking every snippet you use. And if you modify a snippet, you'd have to keep track of that too.

Would you consider a public domain license? Something like the Unlicense?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.