Skip to content
This repository has been archived by the owner on Apr 13, 2022. It is now read-only.

Commit

Permalink
clean up arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
keremciu committed Apr 14, 2021
1 parent 4a1279e commit 5b87ac6
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 17 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ You can install it globally (`npm install -g adr-tool`) or use it with [npx](htt
```sh-session
$ npx adr-tool init
./docs/adr folder is created!
USAGE
$ npx adr-tool create 'Use Markdown Architectural Decision Records'
$ npx adr-tool create Use Markdown Architectural Decision Records
a decision created on ./docs/adr/0000-use-markdown-architectural-decision-records.md
```
# Commands
Expand All @@ -44,11 +43,11 @@ OPTIONS
--status=accepted|deprecated|superseeded
EXAMPLE
$ adr-tool create 'Use ADR Tool'
a decision created on ./docs/adr/0001-use-adr-tool.md
$ adr-tool create Use ADR Tool
a decision created on ./docs/adr/0000-use-adr-tool.md
```

_See code: [src/commands/create.ts](https://github.com/keremciu/adr-tool/blob/v0.0.9/src/commands/create.ts)_
_See code: [src/commands/create.ts](https://github.com/keremciu/adr-tool/blob/v0.1.0/src/commands/create.ts)_

## `adr-tool help [COMMAND]`

Expand Down Expand Up @@ -83,7 +82,7 @@ EXAMPLE
./docs/adr folder is created!
```

_See code: [src/commands/init.ts](https://github.com/keremciu/adr-tool/blob/v0.0.9/src/commands/init.ts)_
_See code: [src/commands/init.ts](https://github.com/keremciu/adr-tool/blob/v0.1.0/src/commands/init.ts)_

## `adr-tool toc`

Expand All @@ -101,5 +100,5 @@ EXAMPLE
./docs/adr/README.md file is created!
```

_See code: [src/commands/toc.ts](https://github.com/keremciu/adr-tool/blob/v0.0.9/src/commands/toc.ts)_
_See code: [src/commands/toc.ts](https://github.com/keremciu/adr-tool/blob/v0.1.0/src/commands/toc.ts)_
<!-- commandsstop -->
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "adr-tool",
"description": "easy CLI for ADR docs",
"version": "0.0.9",
"version": "0.1.0",
"author": "Kerem Sevencan @keremciu",
"bin": {
"adr-tool": "./bin/run"
Expand Down
19 changes: 11 additions & 8 deletions src/commands/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export default class Create extends Command {
static description = 'create a new decision and log it into docs/adr/README.md file'

static examples = [
`$ adr-tool create 'Use ADR Tool'
a decision created on ./docs/adr/0001-use-adr-tool.md
`$ adr-tool create Use ADR Tool
a decision created on ./docs/adr/0000-use-adr-tool.md
`,
]

Expand All @@ -52,19 +52,22 @@ a decision created on ./docs/adr/0001-use-adr-tool.md
}),
}

static args = [{name: 'title'}]
static strict = false

static args = [{name: 'title', description: 'title of the decision'}]

async run() {
const {args, flags} = this.parse(Create)
const {argv, flags} = this.parse(Create)

if (!fs.existsSync(adrDir)) {
error('docs/adr folder is not exist, please run `adr-tools init` command first.')
}

if (!args.title) {
if (argv.length === 0) {
error('please give a title for the decision')
}

const title = argv.join(' ')
let ticket = flags.ticket

if (!ticket) {
Expand Down Expand Up @@ -108,7 +111,7 @@ a decision created on ./docs/adr/0001-use-adr-tool.md

const raw = fs.readFileSync(templateFile, 'utf8')

const cleanTitle = args.title.toLowerCase().trim()
const cleanTitle = title.toLowerCase().trim()
.replace(/[\s_-]+/g, '-') // swap any length of whitespace, underscore, hyphen characters with a single _
.replace(/^-+|-+$/g, '') // remove leading, trailing -
.replace(//g, '')
Expand All @@ -124,7 +127,7 @@ a decision created on ./docs/adr/0001-use-adr-tool.md
const filename = fileIndex + '-' + cleanTitle

const fileData = raw
.replace(/\[short title of solved problem and solution\]/g, newIndex + ' - ' + args.title)
.replace(/\[short title of solved problem and solution\]/g, newIndex + ' - ' + title)
.replace(/\[YYYY-MM-DD when the decision was last updated\]/g, date)
.replace(/\[accepted \| deprecated \| superseded by \[ADR-0005\]\(0005-example.md\)\]/g, status)

Expand All @@ -136,7 +139,7 @@ a decision created on ./docs/adr/0001-use-adr-tool.md

const tocFileRaw = fs.readFileSync(tocFilePath, 'utf8')
const tocFileArray = tocFileRaw.split('\n')
const tocString = `* [ADR-${fileIndex}](${filename}.md) - ${args.title} - [${status}]`
const tocString = `* [ADR-${fileIndex}](${filename}.md) - ${title} - [${status}]`
const tocStopIndex = tocFileArray.indexOf('<!-- tocstop -->')
tocFileArray.splice(tocStopIndex - 1, 0, tocString)

Expand Down
2 changes: 1 addition & 1 deletion src/commands/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,6 @@ export default class Init extends Command {
fs.copyFile(cliTOCFile, adrDir + 'README.md', () => null)

this.log('./docs/adr folder is created!')
this.log("let's create your first decision: `npx adr-tool create 'Use Markdown Architectural Decision Records'`")
this.log("let's create your first decision: `npx adr-tool create Use Markdown Architectural Decision Records`")
}
}

0 comments on commit 5b87ac6

Please sign in to comment.