Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jmfayard/kotlin-cli-starter
Life is too short for Bash programming
https://github.com/jmfayard/kotlin-cli-starter
Last synced: 9 days ago
JSON representation
Life is too short for Bash programming
- Host: GitHub
- URL: https://github.com/jmfayard/kotlin-cli-starter
- Owner: jmfayard
- License: mit
- Created: 2021-05-04T18:47:51.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2024-02-02T13:36:33.000Z (9 months ago)
- Last Synced: 2024-10-12T20:24:22.295Z (23 days ago)
- Language: Kotlin
- Size: 1.4 MB
- Stars: 254
- Watchers: 6
- Forks: 6
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
- awesome-github-repos - jmfayard/kotlin-cli-starter - Life is too short for Bash programming (Kotlin)
README
A starter project to build command-line tools in Kotlin Multiplatform
Contains a re-implementation of a real world CLI tool: [git-standup](https://github.com/kamranahmedse/git-standup)
## Installation
You can install using one of the options listed below
| Source | Command |
| --- | --- |
| Node | npm install -g kotlin-cli-starter
| Installer | `curl -L https://raw.githubusercontent.com/jmfayard/kotlin-cli-starter/main/installer.sh \| sudo sh` |
| Tests | `./gradlew allTests` |
| Kotlin All Platforms | Run `./gradlew allRun` |
| Kotlin JVM | Run `./gradlew run` |
| Kotlin Native | Run `./gradlew install` then `$ git standup` |
| Kotlin Node.JS | Run `./gradlew jsNodeRun` |## Why?
Being able to write your own command-line tools is a great skill to have. Automate all the things!
You can write the CLI tools in Kotlin and reap the benefits of using
- a modern programming language
- modern IDE support
- modern practices such as unit testing and continuous integration
- leverage Kotlin multiplatform libraries
- run your code on the JVM and benefit from a wealth of Java libraries
- or build a native executable, which starts very fast and can be deployed on a computer without the JVMMy strong opinion - weakly held - is that there are only two good kind of Bash scripts:
- the ones that are five lines long or less
- the ones that are written and maintained by others## Work in progress
We want to support Windows, publish on Homebrew and simplify support of shell completion.
Look at the issues https://github.com/jmfayard/kotlin-cli-starter/issues
## What the template contains
The template
- can be run
- with Kotlin/Native via `$ ./gradlew install` and then `git-standup`
- on the JVM with `$ ./gradlew run`
- on Node.JS with `$ ./gradlew jsNodeRun`. The package is published on https://www.npmjs.com/package/kotlin-cli-starter
- has tests that can also be run both
- natively `$ ./gradlew nativeTest`
- on the JVM `$ ./gradlew desktopTest`
- on Node.js `$ ./gradlew jsTest`
- has continuous integration powered by GitHub actions. The code and the tests are run both on native and on the JVM, both on Ubuntu and macOS. See [.github/workflows/runOnGitHub.yml](https://github.com/jmfayard/kotlin-cli-starter/blob/main/.github/workflows/runOnGitHub.yml)
- includes those libraries
- [ktor-client](https://ktor.io/docs/getting-started-ktor-client.html) to make HTTP calls - _Note: only in the branch ktor-client_ See https://github.com/jmfayard/kotlin-cli-starter/issues/15
- [Okio multiplatform](https://square.github.io/okio/multiplatform/) allows reading and writing files
- [kotlin.test](https://kotlinlang.org/api/latest/kotlin.test/) for multi-platform testing
- [CliKt](https://github.com/ajalt/clikt) which parses the command-line arguments in a typesafe way and automatically generates the help and Bash/Zsh/Fish auto-completion
- [mordant](https://github.com/ajalt/mordant) to have colors and styles in the terminal
- [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization) which provides Kotlin multiplatform / multi-format serialization
- [kotlinx.coroutines](https://github.com/Kotlin/kotlinx.coroutines)
- [gradle refreshVersions](https://jmfayard.github.io/refreshVersions/) to simplify dependency management
- contains a work-around of the [missing `runBlocking { ... }` in commonTests](https://github.com/jmfayard/kotlin-cli-starter/issues/9)
- contains an API to work with Files and execute shell subcommands.
## The template reimplements `git-standup`The template reimplements [`git-standup`](https://github.com/kamranahmedse/git-standup) so that you can learn and find inspiration from a real world example.
Simply run it in and it will give you the output from the last working day
Open a directory having multiple repositories and run
```shell
$ ./gradlew install
$ git standup
```![git standup](http://i.imgur.com/4xmkA49.gif)
This will show you all your commits since the last working day in all the repositories inside.
There is auto-completion to see the options
```shell
git standup --help
Usage: git-standup [OPTIONS]Recall what you did on the last working day ..or be nosy and find what
someone else did.Options:
--generate-completion [bash|zsh|fish]
-a, --author TEXT Specify author to restrict search to
-b, --branch TEXT Specify branch to restrict search to
(unset: all branches, "$remote/$branch" to
include fetches)
[... and much more options....]Examples: git-standup -a "John Doe" -w "MON-FRI" -m 3
```## CUSTOMIZE_ME
So are you ready to write your own command-line tool?
Have you an idea of what you want to write yet?
You can find some inspiration in [15 Command Line Tools which Spark Joy in Your Terminal ](https://dev.to/jmfayard/15-command-line-tools-which-spark-joy-in-your-terminal-45ln)
Then click on [Use this GitHub template](https://github.com/jmfayard/kotlin-cli-starter/generate)
There are comments starting with [**CUSTOMIZE_ME**](https://github.com/jmfayard/kotlin-cli-starter/search?q=CUSTOMIZE_ME) in all places you need to customize
Find them with `Edit > File > Find in Files`
## Built with kotlin-cli-starter
- [git-standup](https://github.com/jmfayard/kotlin-cli-starter)
- [httpie.kt](https://github.com/raychenon/httpie.kt)
- ..._Have you used the template to build something? Please advertise it here_ 🙏🏻