Batch, Developer Tool, Plugin, Programming, Uncategorized

Easily create CMD plugins with the FnCreator template generator.

Professional Batch plugins take a while to develop, and many developers have their own collection of templates to easily skeleton a project. Because of this, Karanveer Chouhan (Kvc) created his own template (skeleton project) generator for the public to use. Developers can find a lot of utility in this application, and we will discuss it’s features in this article.

RELATED VIDEO

WHAT IS A TEMPLATE?

A template is a skeleton project. It contains the basic structure of a program that you can expand (or flesh out) the systems afterwards. Templates give developers the opportunity to focus more on their client or applications needs, and reduces the human error in the basic aspects of your program, such as parameters. A variety of IDE’s have templates built into their software for a variety of languages and use cases. In Batch, however, there is no IDE that has templates readily made.

Karanveer Chouhan developed this FnCreator application with this in mind. And now you can easily skeleton a project, and then tailor it to your needs. I am interested in seeing if this application will develop more in the future, and perhaps integrate with things like GitHub or provide compatibility systems for other plugins out of the box.

DEMONSTRATING FNCREATOR WITH FOO.BAT

Let’s consider an example application we have developed for this template system. It’s a very simple application, but it will serve it’s purpose:

@echo off
color 0f
title "Foo.bat"
echo Hello, World!
set a=200
pause >NUL
echo All done, bye!
exit /b 23

The best practice is going to be to create a project directory and then to call this function to create our project. You need to suggest the name, language, author and location of the project in that order (beware, it creates a new file). We will do it like so:

C:\>mkdir FooProject

C:\>FnC Foo BAT Zeek FooProject

 Generated "..\Foo\Src\Tok.bat" ...

 Generating README.md File...
 Generated "..\Foo\README.md" ...

 Generating CHANGELOG.md File...
 Generated "..\Foo\CHANGELOG.md" ...

It will create a directory inside of our project folder named Foo in this case, and it will contain the program template that we can modify. The structure of the template is as follows:

C:
│   CHANGELOG.md // an empty changelog
│   README.md // an empty readme
│
├───bin // a folder to store our binaries (if we wish to pack them)
└───Src // the source folder
    │   Foo.bat // the main file with the program structure
    │
    └───Files // an additional file for external libraries/etc

THE TEMPLATE FILE

Let’s take a look inside of Foo.bat. This is our main application file, and it has a variety of template code in it that will set up the environment for our program to execute. I will copy the default contents of this file (which applies to anything made using this application) and explain some of them below. I will use // comments in bold to explain the behavior.

@Echo off
Setlocal EnableDelayedExpansion

Set _path=%LocalAppdata%\Tok
Set path=%path%;%_path%;%cd%;%cd%\Files; // This sets an appdata path for extra files
Cd Files >nul 2>nul
If Not exist "%_path%" (Md "%_path%")

REM THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY
REM KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
REM WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
REM AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
// This is a general license agreement for liability, can be removed
REM HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
REM WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
REM OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
REM DEALINGS IN THE SOFTWARE.

REM This program is distributed under the following license: xxx

// A simple explanation of the program
REM ================= ABOUT THE PROGRAM =================
REM This program is created by Zeek at 'Sun 01/23/2022 - 18:44'
REM This program can _______________________________________________________
REM For More Visit: www.batch-man.com

// Version number
REM Setting version information...
Set _ver=_._

// This is a default set of parameters that route the user to the help menu.
REM Checking for various parameters of the function...
for %%A in ("/?" "--help" "-h" "-?" "-help") do (if /i "%%A" == "%~1" (goto :help))
If /i "%~1" == "ver" (Echo.%_ver%&Goto :End)
If /i "%~1" == "" (goto :help)

If /i "%~2" == "" (goto :help)
If /i "%~3" == "" (goto :help)
If /i "%~4" == "" (goto :help)
If /i "%~5" == "" (goto :help)
If /i "%~6" == "" (goto :help)
If /i "%~7" == "" (goto :help)
If /i "%~8" == "" (goto :help)
If /i "%~9" == "" (goto :help)

// This will save the parameters to a set of variables, it is optional as well.
REM Saving parameters to variables...
Set _1=%~1
Set _2=%~2
Set _3=%~3
Set _4=%~4
Set _5=%~5
Set _6=%~6
Set _7=%~7
Set _8=%~8
Set _9=%~9

REM Starting Main Program...
:Main
// The main program functionality should be put here.
// This is the equivalent of the start of the batch file.

Goto :End // This will route to the end of the file, it is essentially an exit.


:End
Goto :EOF


:Help // This is the help menu for the function, ... is a continued list of help // information I removed for clarity. You can edit it for your needs.
Echo.
Echo. This function will _______________________________________________________
echo. It will help in __________________________________________________________
Echo. CREDITS: Tok %_ver% by Zeek
echo.
echo. Syntax: call Tok [] [] [] [] [] [] [] [] []
echo. Syntax: call Tok [help , /? , -h , -help]
echo. Syntax: call Tok ver
echo.
echo. Where:-
echo.
echo. ver		: Displays version of program
echo. help		: Displays help for the program

...
Goto :End

CONCLUSION/DOWNLOAD

I hope this article has demonstrated the usefulness of this application. It will allow you to easily skeleton your application, and start working on important parts immediately. Like any batch application, the template can also be modified, so it provides a very powerful platform for developers. You can download the application on our GitHub page, as well as submit errors and questions there. We are always looking for improvement. Thank you for reading.

Leave a Reply