Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Creating a CLI to interface with the tool #106

Open
Syakhisk opened this issue Nov 5, 2023 · 2 comments
Open

Creating a CLI to interface with the tool #106

Syakhisk opened this issue Nov 5, 2023 · 2 comments

Comments

@Syakhisk
Copy link

Syakhisk commented Nov 5, 2023

Hey, great tools!
Unfortunately I don't use vscode. Is there any plan to make this tool usable from the CLI? or do you have any pointers if I want to implement a CLI for this?

@MichaelCurrin
Copy link
Owner

MichaelCurrin commented Nov 18, 2023

Hi, thanks for the interest. There is actually a CLI option.

https://github.com/MichaelCurrin/auto-commit-msg/tree/master/shell#autofill-scripts

I am missing pieces that make it easy to bundle and install. However I can send you something so you can try it out yourself, for Linux.

Setup

Make sure /usr/local/bin is your PATH variable

echo $PATH

Then continue.

  1. Go to the v0.26.2 release https://github.com/MichaelCurrin/auto-commit-msg/releases/tag/v0.26.2
  2. Download the .vsix file
  3. Unzip it to for your user.
    sudo apt install unzip
    unzip auto-commit-msg-0.26.2.vsix -d ~/Downloads/auto-commit-msg
    
  4. Create the CLI entry point as below. as acm.sh in /usr/local/bin
  5. Make it executable
    chmod +x /usr/local/bin/acm.sh
  6. Test it generates a message. (no commit made here)
    $ cd my-repo
    $ git add ...
    $ acm.sh
    ...
    

Here is the script

#!/usr/bin/env bash
set -e

DIFF_FLAGS='--name-status --find-renames --find-copies --no-color'
CHANGES=$(git diff-index $DIFF_FLAGS HEAD)

MESSAGE=$(node ~/Downloads/auto-commit-msg/extension/out/cli.js "$CHANGES")
echo "$MESSAGE"

Usage

You can run it like this

git commit --edit -m "$(acm.sh)"

And that is of course easier if you add a Bash alias or a Git alias

Here for Git config:

[alias]
    c = '! git commit --edit -m "$(autofill.sh)"'

Then just

git c

@MichaelCurrin
Copy link
Owner

MichaelCurrin commented Nov 18, 2023

If you want an updated version, you'll have to download and unzip whenever there is a new release.

If you have any ideas or can help with making setup and update smoother, that would be great.

Ideas

Rollup

I did some experiments today but got stuck because of the a mix of ES modules and CJS modules and fighting with TypeScript and Rollup.

I found a way to bundle the out/cli.js file the (CLI entry point of my tool) as a single JS file with dependencies, using the Rollup tool and plugins. I need to make a change to a ton of imports to make them use .js explicitly for that to work properly.

Shell script distribution

I am thinking of a pipeline solution to make the .sh file installable with one or more JS files.

At the least using curl.

But there are more professional tools I've seen for making Bash tools easy to install and update.

NPM package

Another idea I had is to do away with the Bash + JS option and instead make my tool installable as an NPM package (I've seen NPM packages come as a binary that was compiled from Go for example).

Then you would install my tool as

npm i auto-commit-msg

And run like

git commit --edit -m "$(npx auto-commit-msg)"

And also this could be expanded to work on Windows if the .sh script I provided worked as .cmd / powershell

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants