Skip to content

Commit

Permalink
move version to --version, mimic golang-style help text
Browse files Browse the repository at this point in the history
  • Loading branch information
ExperiBass committed Oct 17, 2024
1 parent 0d4cf03 commit 683bafa
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 27 deletions.
36 changes: 18 additions & 18 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -18,29 +18,30 @@ npm link --global
```

# Usage

```
Usage: cli-pride-flags [options...] flag
Usage:
cli-pride-flags [options...] [flag]
Options:
--blend, -b flag[,factor] Blend two flags together, with an optional decimal factor
--character, -c char Character to use to draw the flag
--gradient, -g Make the flag a smooth gradient
--height, -h int The height of the flag, in characters
--help, -? Display this help text
--install-completion Install tabtab shell completion
--live, -l Hold the terminal and redraw the flag upon resize, closing when any key is pressed
--newline, -n Prints a newline at the end of each line
--printname, -p Prints name of the randomly chosen flag before the flag. Only works with --random
--random, -r Displays a random flag! This ignores any passed flags.
--use-flag-height Uses the number of stripes the flag has as its height. Overrides --height
--use-flag-width Uses the number of stripes the flag has as its width. Overrides --width
--vertical, -v Display the flag, but vertically
--width, -w int The width of the flag, in characters
-b, --blend flag[,factor] Blend two flags together, with an optional decimal factor
-c, --character char Character to use to draw the flag
-g, --gradient Make the flag a smooth gradient
-h, --height int The height of the flag, in characters
-?, --help Display this help text
--install-completion Install tabtab shell completion
-l, --live Hold the terminal and redraw the flag upon resize, closing when any key is pressed
-n, --newline Prints a newline at the end of each line
-p, --printname Prints name of the randomly chosen flag before the flag. Only works with --random
-r, --random Displays a random flag! This ignores any passed flags.
--use-flag-height Uses the number of stripes the flag has as its height. Overrides --height
--use-flag-width Uses the number of stripes the flag has as its width. Overrides --width
--version Print installed version
-v, --vertical Display the flag, but vertically
-w, --width int The width of the flag, in characters
```
Example: `cli-pride-flags -l trans` would display the trans flag and hold the terminal.

# Screenshots

Theres a page previewing all the flags on [my site :3](https://experibassmusic.eth.limo/flags.html)

Some screenshots are below!
Expand All @@ -50,7 +51,6 @@ Some screenshots are below!
![bunch of flags and help text :D](./screenies/2.png)

# Issues

- none :3

# TODO
Expand Down
19 changes: 12 additions & 7 deletions src/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ const columns = require('cli-columns')
const tabtab = require('tabtab')
/// import local files
const flags = require('unified-pride-flags')
const { name: packageName, version } = require('../package.json')
const { name: programName, version } = require('../package.json')
const { randNum, interpolateColor, FlagColors, ArgParser } = require('./util')

const cliOptions = {
help: { type: 'boolean', short: '?', description: 'Display this help text' },
version: {type: 'boolean', description: 'Print installed version'},
gradient: {
type: 'boolean',
short: 'g',
Expand Down Expand Up @@ -107,10 +108,9 @@ function help() {
flagList.push(flagLine)
}

console.log(`Usage:\n ${chalk.green(packageName)} ${chalk.blueBright('[options...]')} ${chalk.yellow('flag')}`)
console.log(`Options:\n${argparser.listOptions()}`)
console.log(`Flags:\n${chalk.greenBright(columns(flagList, { padding: 1 }))}`)
console.log(chalk.green(`${packageName} ${chalk.blueBright(`v${version}`)}`))
console.log(`Usage:\n ${chalk.green(programName)} ${chalk.blueBright('[options...]')} ${chalk.yellow('[flag]')}\n`)
console.log(`Options:\n${argparser.listOptions()}\n`)
console.log(`Flags:\n${chalk.green(columns(flagList, { padding: 1 }))}`)
}

function completion(env = {}) {
Expand Down Expand Up @@ -281,8 +281,8 @@ function draw() {
if (options['install-completion']) {
tabtab
.install({
name: packageName,
completer: packageName,
name: programName,
completer: programName,
})
.then(() => {
process.exit(0)
Expand All @@ -307,6 +307,11 @@ if (!chalk.supportsColor) {
}
chalk.level = 3 // try to use truecolor

if (options.version) {
console.log(`${chalk.green(`${programName}`)} v${chalk.blueBright(`${version}`)}`)
process.exit()
}

if (options.help || (!options.random && !Object.keys(flags).includes(CHOSEN_FLAG))) {
/// this is less cursed lol
help()
Expand Down
3 changes: 1 addition & 2 deletions src/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,7 @@ class ArgParser {
const SPACES = 20 /// option starting distance from the left
/// keep this
for (const [long, info] of Object.entries(this.#options).sort((a,b) => a[0].localeCompare(b[0]))) {
let optionHelpString = ' '
console.log(long)
let optionHelpString = ' ' /// prepend 2 spaces
if (info.short) {
optionHelpString += `-${info.short}, `
}
Expand Down

0 comments on commit 683bafa

Please sign in to comment.