Yuxia gossip - NewCode

preface

   in my work and study, I have configured a VSCode to learn the C language. I need to create code files frequently, and there is often a fixed template in it, such as the following:

#define _CRT_SECURE_NO_WARNINGS

#include <stdlib.h>
#include <stdio.h>

int main(int argc,char* argv[])
{
    /* code */
    system("pause");
    return 0;
}

  you can't copy and paste files one by one, can you? Especially when the amount of code goes up, it is particularly inconvenient. But if you learn more languages: C + +, Python, JavaScript, and blogging, you need MD. These can be well solved in VSCode, but it is very troublesome to manage. So I think why not write a software to realize this kind of management? NewCode was written. Originally, it was a language and a version. Now you only need to configure it to implement a NewCode program to manage a large number of single file code.

Warehouse address

  currently only on GitHub. When the software is almost ready, move to Gitee: https://github.com/Wing-summer/NewCode

Coding language and compiling environment

    I use the higher version of VS2020 at present and write it in C# language. I can download and compile it.

introduction

  when you double-click run, this interface will appear.

   that is, when you directly run the program without parameters, only help will be displayed and any key will be pressed to exit.
   all commands of this tool are case insensitive, as shown in the following examples:

NewCode -t cpp -p C:\test -k
NewCode -st c
NewCode -t cpp -p C:\test -f "hello" " world"
NewCode -q

  I don't understand. Let's see the meaning of each parameter:

-t | -type: Type, configuration json Code block id
-p | -path: Path, the path to create the file. If the suffix is omitted, the json Configuration based addition
-k | -keepalive | -keep | -alive: After executing the program, it will not exit, keep running, and can execute other commands
-f | -fill | -param: Fill in variable parameters, which is very useful for templates. See the example for how to write appropriate parameters
-st | -settype: After the program runs, if it is not specially set, the first one in the configuration file will be called by default
-q: Exit the program, only in keepalive Effective in environment
-add [type] [path] {ext}: Add to type The content is id ,Then use path As a path, note that the recommended path is a relative path, if any ext Parameter is represented by it
 Is an extension.
-mod [type] p={path} ext={ext}: modify type Configuration in
-del [type]: Delete to type == id Content of
-cls: Clean up all configurations
-showAll: Display all configuration key values
-showInfo [type]: Displays all information for this type
-showtype [type]: Same function -showInfo
-r | -restart: Restart the program if it is followed by # As a parameter description, restart with administrator privileges. Restart has the - k parameter by default.
-curdir | -pwd: Displays the current working directory
-prodir: Displays the directory where the program is located
-cd: It is often useful to change the current directory
-setenv: Add environment variables to the directory where the program is located
-delenv: Delete the environment variable in the directory where the program is located

   here is a description: if it is in the keepalive state, that is, when it runs with the parameter - k. You do not need to enter NewCode. If the above parameters are not, the program will call the cmd command to run. If it is regarded as a cmd command, it must not start with the - character, otherwise it is regarded as an internal command.
  enter several commands to test:

  it is more comfortable to cooperate with the interrupt function of VSCode:

Write configuration

   the file configuration directory is recommended to be a relative directory, and the use of a relative directory refers to the relative directory to this program. For example, I configure a cpp template as follows:

#include <iostream>
using namespace std;

int main(int argc,char* argv[])
{
    // Written By |[0]|
    system("pause");
    return 0;
}

   you may find a special character | [0] | what does this mean? For C #, if you format this string, it is equivalent to the following code:

string.Format( "Written By {0}" , arg );

    do you know a lot about this code? Because the code syntax, such as curly braces in C + +, C, c#, Java and other languages, is meaningful. In order to realize the formatting function, I just escaped this. That is, this format supports all c# code formatting.
   fix the configuration file and save it in UTF-8 code. This is the protocol my program follows. Remember its relative path, assuming code \ CPP txt.
  then we go to the program directory on the console and run the program with parameters:

NewCode -add cpp code\cpp.txt

  in this way, we will successfully configure it in the configuration file.
   if the program location is fixed, it is recommended to set the environment variable for it, which needs to be added. However, our program has encapsulated this function and needs administrator permission, but it is usually started with normal permission. We can use the following command in keepalive mode:

-r #

    # represents the administrator authority, and then starts the program with the administrator authority of keepalive mode, and then enters the following command:

-setenv

  this will add environment variables to the directory where the program is located. Don't move its directory at this time to prevent invalidation.

Generate use

  after the above configuration, we can use the program to create it. We can enter the following command:

Newcode -t cpp -p D:\test -f wingsummer

  the meaning of the above command is to create a file test on disk D cpp file, format wingsummer as a parameter, call the configuration cpp, that is, the generated file we configured before, and open it, the following results will be obtained:

#include <iostream>
using namespace std;

int main(int argc,char* argv[])
{
    // Written By wingsummer
    system("pause");
    return 0;
}

   however, if there is no subsequent format fill command, you will get a warning and fill it with an empty string, that is, the following command:

Newcode -t cpp -p D:\test

  that is, the following results:

#include <iostream>
using namespace std;

int main(int argc,char* argv[])
{
    // Written By
    system("pause");
    return 0;
}

   this can be used normally. If you want to use it better, please read the source code in detail and make the code you are used to. After all, the tools you make are the best use of your own experience.

About submitting bugs

  if you write in your spare time, you will inevitably make mistakes. If there is a Bug, please submit it. If you have other requirements, please write the C# code yourself and make a Pull Request on GitHub. I won't realize the Request function I don't need.

agreement

  the software uses MIT protocol, which means that you can modify its code for legitimate purposes to meet your own needs. However, please do not use it for commercial purposes at will, unless you modify the code more than 80% of the total code. You can write your contribution to the file yourself, but you cannot delete the information and description of the original author.

Added by Josh18657 on Tue, 11 Jan 2022 15:45:54 +0200