Support detecting args that is specified but with no values
Open
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 1.3k
- Forks
- 58
- PR merge metrics
- No merged PRs in 30d
Description
Describe the feature
Generally I have to using customized args parser to write tje following code. I was hope that citty could support the requirement said in the title, since it already use mir under the hood.
import process from 'node:process'
import parseArgs from 'mri'
import { defineCommand, runMain, showUsage } from 'citty'
import { ensureConfig, logger } from './utils.js'
import { bundle } from './commands/bundle.js'
import {
version,
description,
} from '../../package.json' assert { type: 'json' }
import { DEFAULT_CONFIG_FILENAME } from './constants.js'
interface ParsedArgs {
config?: string | true
c?: string | true
// `citty` intercept the help option, so we don't need to deal with it
// help?: boolean
// h?: boolean
}
const main = defineCommand({
meta: {
name: 'rolldown',
version,
description,
},
args: {
config: {
type: 'string',
alias: 'c',
description:
'Use this config file (if argument is used but value is unspecified, defaults to `rolldown.config.js`)',
},
help: {
type: 'boolean',
alias: 'h',
description: 'Show this help message',
},
},
async run(_ctx) {
// FIXME: `citty` doesn't support detecting if an argument is unspecified
const parsedArgs = parseArgs<ParsedArgs>(process.argv.slice(2))
let argConfig = parsedArgs.c || parsedArgs.config
if (argConfig) {
// If config is specified, we will ignore other arguments and bundle with the specified config
if (argConfig == true) {
argConfig = DEFAULT_CONFIG_FILENAME
}
await bundle(argConfig)
return
}
showUsage(main)
},
})
runMain(main)
Additional information
- Would you be willing to help implement this feature?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting citty's argument parsing around defineCommand and runMain, then compare how the bundled mri parser represents an option with no value. Add coverage for distinguishing an explicitly provided option from an omitted one, including the config example, and verify the existing CLI behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- cli
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100