Skip to content

Commit

Permalink
Merge pull request #75 from vseventer/yargs-update
Browse files Browse the repository at this point in the history
Update yargs dependency & usage
  • Loading branch information
vseventer authored Dec 10, 2022
2 parents 09b55bb + af1584d commit b57b3c5
Show file tree
Hide file tree
Showing 66 changed files with 1,652 additions and 1,451 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Changelog

## 4.0.0-dev
* Updated `sharp` dependency.
* Updated `yargs` dependency.
* Added [`affine`](https://sharp.pixelplumbing.com/api-operation#affine) command.
* Added `--background`, `--basename`, and `--skipBlanks` to `tile` command.
* Removed `--density` from `joinChannel` command.
* Renamed `--band` to `--channel` (`extractChannel` command).
* Updated `composite` command to accept multiple images ([#73](https://github.com/vseventer/sharp-cli/issues/73)).
* Updated `--kernel` option usage in `convolve` command.
* Updated `--offset` option usage in `linear` command.
* Updated `matrix` positional usage in `recomb` command.

## 3.0.0 (September 15, 2022)
* Added [`--background`](https://sharp.pixelplumbing.com/api-resize#trim) when trimming images.
* Added [`--minSize` and `--mixed`](https://sharp.pixelplumbing.com/api-output#webp).
Expand Down
142 changes: 74 additions & 68 deletions README.md

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion bin/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,8 @@
// Strict mode.
'use strict'

// Package modules.
const { hideBin } = require('yargs/helpers')

// Run.
require('../lib')(process.argv.slice(2))
require('../lib')(hideBin(process.argv))
10 changes: 3 additions & 7 deletions cmd/channel-manipulation/bandbool.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,20 @@ const constants = require('../../lib/constants')
const queue = require('../../lib/queue')

// Configure.
const options = {
const positionals = {
operator: {
choices: constants.BOOL,
desc: 'Operator to perform that bitwise operation',
type: 'string'
desc: 'Operator to perform that bitwise operation'
}
}

// Command builder.
const builder = (yargs) => {
const optionNames = Object.keys(options)
return yargs
.strict()
.example('$0 bandbool and', 'The output will be a single channel image where each pixel `P = R & G & B`')
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-channel#bandbool')
.options(options)
.global(optionNames, false)
.group(optionNames, 'Command Options')
.positional('operator', positionals.operator)
}

// Command handler.
Expand Down
13 changes: 6 additions & 7 deletions cmd/channel-manipulation/ensure-alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
const queue = require('../../lib/queue')

// Configure.
const options = {
const positionals = {
alpha: {
default: 1,
desc: 'Alpha transparency level',
Expand All @@ -40,13 +40,12 @@ const options = {

// Command builder.
const builder = (yargs) => {
const optionNames = Object.keys(options)
return yargs
.strict()
.example('$0 ensureAlpha', 'The output will be a 4 channel image with a fully-opaque alpha channel')
.example('$0 ensureAlpha 0', 'The output will be a 4 channel image with a fully-transparent alpha channel')
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-channel#removealpha')
.options(options)
.global(optionNames, false)
.group(optionNames, 'Command Options')
.positional('alpha', positionals.alpha)
}

// Command handler.
Expand All @@ -56,8 +55,8 @@ const handler = (args) => {

// Exports.
module.exports = {
command: 'ensureAlpha',
describe: 'Ensure alpha channel, if missing',
command: 'ensureAlpha [alpha]',
describe: 'Ensure the output image has an alpha transparency channel',
builder,
handler
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,34 +31,30 @@ const constants = require('../../lib/constants')
const queue = require('../../lib/queue')

// Configure.
const options = {
band: {
choices: constants.BAND,
desc: 'The band number to extract',
type: 'string'
const positionals = {
channel: {
choices: constants.CHANNEL,
desc: 'The channel/band number to extract'
}
}

// Command builder.
const builder = (yargs) => {
const optionNames = Object.keys(options)
return yargs
.strict()
.example('$0 extractChannel green', 'The output will contain the green channel of the input image')
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-channel#extractchannel')
.options(options)
.global(optionNames, false)
.group(optionNames, 'Command Options')
.positional('channel', positionals.channel)
}

// Command handler.
const handler = (args) => {
return queue.push(['extractChannel', (sharp) => sharp.extractChannel(args.band)])
return queue.push(['extractChannel', (sharp) => sharp.extractChannel(args.channel)])
}

// Exports.
module.exports = {
command: 'extractChannel <band>',
command: 'extractChannel <channel>',
describe: 'Extract a single channel from a multi-channel image',
builder,
handler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,12 @@
// Strict mode.
'use strict'

// Standard lib.
const path = require('path')

// Local modules.
const queue = require('../../lib/queue')

// Configure.
const options = {
density: {
desc: 'Number representing the DPI for vector images',
defaultDescription: 72,
nargs: 1,
type: 'number'
},
const positionals = {
images: {
coerce: (arr) => arr.map(path.normalize), // Positional arguments need manual normalization.
desc: 'One or more images',
normalize: true,
type: 'array'
Expand All @@ -50,20 +40,15 @@ const options = {

// Command builder.
const builder = (yargs) => {
const optionNames = Object.keys(options)
return yargs
.strict()
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-channel#joinchannel')
.options(options)
.global(optionNames, false)
.group(optionNames, 'Command Options')
.positional('images', positionals.images)
}

// Command handler.
const handler = (args) => {
return queue.push(['joinChannel', (sharp) => {
return sharp.joinChannel(args.images, { density: args.density })
}])
return queue.push(['joinChannel', (sharp) => sharp.joinChannel(args.images)])
}

// Exports.
Expand Down
1 change: 1 addition & 0 deletions cmd/channel-manipulation/remove-alpha.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const queue = require('../../lib/queue')
const builder = (yargs) => {
return yargs
.strict()
.example('$0 removeAlpha', 'The output will be without an alpha channel')
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-channel#removealpha')
}

Expand Down
1 change: 1 addition & 0 deletions cmd/colour-manipulation/greyscale.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const queue = require('../../lib/queue')
const builder = (yargs) => {
return yargs
.strict()
.example('$0 greyscale', 'The output will contain three identical color channels')
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#greyscale')
}

Expand Down
11 changes: 4 additions & 7 deletions cmd/colour-manipulation/pipeline-colourspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,21 @@ const constants = require('../../lib/constants')
const queue = require('../../lib/queue')

// Configure.
const options = {
const positionals = {
colourspace: {
alias: 'colorspace',
choices: constants.COLOURSPACE,
desc: 'Pipeline colourspace',
type: 'string'
desc: 'Pipeline colourspace'
}
}

// Command builder.
const builder = (yargs) => {
const optionNames = Object.keys(options)
return yargs
.strict()
.example('$0 pipelineColourspace rgb16', 'Run the pipeline in 16 bits per channel RGB')
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#tocolourspace')
.options(options)
.global(optionNames, false)
.group(optionNames, 'Command Options')
.positional('colourspacae', positionals.colourspace)
}

// Command handler.
Expand Down
10 changes: 4 additions & 6 deletions cmd/colour-manipulation/tint.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,20 @@
const queue = require('../../lib/queue')

// Configure.
const options = {
const positionals = {
rgb: {
desc: 'String parsed by the color module to extract chroma values',
desc: 'Parsed by the color module to extract chroma values',
type: 'string'
}
}

// Command builder.
const builder = (yargs) => {
const optionNames = Object.keys(options)
return yargs
.strict()
.example('$0 tint "rgb(255, 240, 16)"')
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#tint')
.options(options)
.global(optionNames, false)
.group(optionNames, 'Command Options')
.positional('rgb', positionals.rgb)
}

// Command handler.
Expand Down
11 changes: 4 additions & 7 deletions cmd/colour-manipulation/tocolourspace.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,21 @@ const constants = require('../../lib/constants')
const queue = require('../../lib/queue')

// Configure.
const options = {
const positionals = {
colourspace: {
choices: constants.COLOURSPACE,
default: 'srgb',
desc: 'The output colourspace',
type: 'string'
desc: 'The output colourspace'
}
}

// Command builder.
const builder = (yargs) => {
const optionNames = Object.keys(options)
return yargs
.strict()
.example('$0 toColourspace rgb16', 'Output 16 bits per pixel RGB')
.epilog('For more information on available options, please visit https://sharp.pixelplumbing.com/api-colour#tocolourspace')
.options(options)
.global(optionNames, false)
.group(optionNames, 'Command Options')
.positional('colourspace', positionals.colourspace)
}

// Command handler.
Expand Down
Loading

0 comments on commit b57b3c5

Please sign in to comment.