spotless icon indicating copy to clipboard operation
spotless copied to clipboard

feat: introduce cli for invoking spotless from shell without any build tool

Open simschla opened this issue 8 months ago • 8 comments

Motivation

Sometimes, I would love to be able to quickly format some files from my command line, like I'm used to when working on bigger projects, where we've introduced spotless-gradle or spotless-maven. There was no easy way to get the modularity or functionality of spotless without introducing a build for applying the plugin.

So I've asked myself: What if there were a command line interface, a binary that runs superfast and can simply be invoked from the shell without any further setup and even for single files?

This is my proposal to start building such a spotless cli tool - I'm very interested in what @nedtwigg (and of course other contributors and users) think about this approach.

Current State

The current code is still a WIP and has some (very 😉) rough edges that we'd need to smooth out before any of this could be merged, but I think the existing code shows that this could indeed work - and I love it already from using it in my local tests.

The general Idea is to build a cli, that can be used like a "pipeline" (similar to how current spotless-build-plugins are working).

E.g. I'd like to be able to invoke it somehow like this

spotless --generic-params-like-target step-1-eg-like-gjf --params-for-step1 step-2-eg-copyright --params-for-step-2 ...

The current WIP provides the ability to set target-globs for selecting files, allows google-java-format, prettier and copyright/license-header. Adding further formatters is most probably a notable amount of (diligent) work, but I think the current code shows that we can get there.

Example Usage Output

Current API looks like this (showing --help usage output):

  1. General Usage: SCR-20250207-sxdk

  2. License Header: SCR-20250207-sxgw

  3. Google Java Format SCR-20250207-sxkz

  4. Prettier SCR-20250207-sxoh

simschla avatar Feb 07 '25 21:02 simschla