Skip to content

Commit

Permalink
feat: allow to configure default values
Browse files Browse the repository at this point in the history
Defaults values can be configured in the `.env` files. For more information, see the README.md file.
  • Loading branch information
jamacku committed Aug 14, 2024
1 parent 9f7a817 commit 6a6afa3
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,17 @@ Make sure to store your JIRA Personal Access Token (PAT) in the `~/.config/story
JIRA_API_TOKEN="exaple-token"
```

> [!TIP]
>
> You can also set default values for the `assignee`, `developer`, and `component` fields in the `~/.config/storypointer/.env` or `~/.env.storypointer` file:
>
> ```bash
> # ~/.config/storypointer/.env
> ASSIGNEE="your-jira-username"
> DEVELOPER="your-jira-username"
> COMPONENT="your-component"
> ```
### Using Node.js
```bash
Expand Down
4 changes: 2 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import '@total-typescript/ts-reset';

import { Jira } from './jira';
import { getLegend } from './legend';
import { raise, tokenUnavailable } from './util';
import { getOptions, raise, tokenUnavailable } from './util';

import {
colorPrioritySchema,
Expand Down Expand Up @@ -50,7 +50,7 @@ const cli = async () => {

program.parse();

const options = program.opts();
const options = getOptions(program.opts());

if (options.legend) {
console.log(getLegend());
Expand Down
17 changes: 17 additions & 0 deletions src/util.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { OptionValues } from 'commander';

export function raise(error: string): never {
throw new Error(error);
}
Expand All @@ -7,3 +9,18 @@ export function tokenUnavailable(): never {
`JIRA_API_TOKEN not set.\nPlease set the JIRA_API_TOKEN environment variable in '~/.config/storypointer/.env' or '~/.env.storypointer' or '~/.env.'`
);
}

export function getDefaultValue(
envName: 'ASSIGNEE' | 'COMPONENT' | 'DEVELOPER'
) {
return process.env[envName];
}

export function getOptions(inputs: OptionValues): OptionValues {
return {
...inputs,
assignee: inputs.assignee || getDefaultValue('ASSIGNEE'),
component: inputs.component || getDefaultValue('COMPONENT'),
developer: inputs.developer || getDefaultValue('DEVELOPER'),
};
}

0 comments on commit 6a6afa3

Please sign in to comment.