Commenteer - Code Commenting Made Easy
​​​​​​​​​​​​​​​​​​​​​​​​​

Commenteer: Code Commenting Made Easy

Introduction

Recently I released a new bit of rust code: Commenteercrates.io version. This software was designed with one simple thing in mind. To add comment headers to large code-bases without the need to manually open every fi​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​le in a text editor. Most "heavy" editors these days can do this for you but ar​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​e a bear to use. Eclipse, any of the JetBrains IDEs, and Emacs all support this. You can even achieve this in Vim. But for me this seemed over-complicated for the task.

Commenteer is a simple command line utility that ta​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​kes a few simple arguments and automates the whole process. Here is the help info:

Commenteer 0.2.1
Chad Baxter <mistercbax@gmail.com>
Add comment headers to code.

USAGE:
    commenteer [FLAGS] [OPTIONS] --input <input>...

FLAGS:
    -h, --help       Prints help information
    -r, --recurse    Add header to every text file in the specified path.
    -V, --version    Prints version information
    -v, --verbose    Show verbose information about the operation

OPTIONS:
    -c, --comment-file <comment-file>    A path to a file containing the header you would like to add.
    -t, --comment-text <comment-text>    A string containing the header you would like to add. Can contain control
                                         characters that use backslashes(\n, \t etc).
    -n, --ignore <ignore>...             Paths to files you would like to exclude from being modified
    -i, --input <input>...               List of paths or files to add a header to.

As you can see Commenteer supports rea​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ding a comment header from a file or accepting it from the command line. It supports recursive commenting of all code in a directory as well as ignoring specific files.

an example command for reading from a f​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ile and applying changes recursively:

comment.txt

/*╭──────────────────────╮
  │ Author: Chad Baxter  │
  │ Date:                │
  │ For:                 │
  ╰──────────────────────╯*/

commenteer -r -c ../comment.txt -i ./

An example command using an argument to accept the comment:

commenteer -r -t "/*╭──────────────────────╮\n │ Author: Chad Baxter │\n │ Date: │\n │ For: │ \n╰──────────────────────╯*/"

Future plans

My hopes are to give this program the ability to identify the types of code and apply the correct comment syntax to provid​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ed comment text. For example // for C-style comments # for bash style comments etc. I am thinking that simply parsing any code for the existence of a commen​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​t and using that comment style may work. Or perhaps just adding a hardcoded list of comment styles and allowing selection of a style from the cli.

The ugly

This application is currently pretty rough around the edges and has a number of bugs that could really mess up your code if you aren't care​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ful. Always commit your changes before using Commenteer and roll back your repository if it does mess things up. I am currently aware of an bug in ignore list processing that may cause only the first ignored file to be recognized. This is a problem w​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​​ith how my application handles clap arguments. Contributions are welcome at: https://github.com/LogoiLab/commenteer

​​​​​​​​​​​​​​​​​​​​​​​​​