@karmaniverous/get-dotenv 6.1.0 → 6.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +18 -14
- package/dist/cli.mjs +645 -350
- package/dist/getdotenv.cli.mjs +645 -350
- package/dist/index.mjs +645 -350
- package/dist/plugins-aws.d.ts +4 -3
- package/dist/plugins-aws.mjs +319 -170
- package/dist/plugins-batch.d.ts +2 -1
- package/dist/plugins-batch.mjs +76 -41
- package/dist/plugins-cmd.d.ts +2 -1
- package/dist/plugins-cmd.mjs +29 -15
- package/dist/plugins-init.d.ts +2 -1
- package/dist/plugins-init.mjs +158 -118
- package/dist/plugins.d.ts +7 -2
- package/dist/plugins.mjs +645 -350
- package/dist/templates/cli/plugins/hello/defaultAction.ts +27 -0
- package/dist/templates/cli/plugins/hello/index.ts +26 -0
- package/dist/templates/cli/plugins/hello/options.ts +31 -0
- package/dist/templates/cli/plugins/hello/strangerAction.ts +20 -0
- package/dist/templates/cli/plugins/hello/types.ts +13 -0
- package/dist/templates/defaultAction.ts +27 -0
- package/dist/templates/hello/defaultAction.ts +27 -0
- package/dist/templates/hello/index.ts +26 -0
- package/dist/templates/hello/options.ts +31 -0
- package/dist/templates/hello/strangerAction.ts +20 -0
- package/dist/templates/hello/types.ts +13 -0
- package/dist/templates/index.ts +23 -22
- package/dist/templates/options.ts +31 -0
- package/dist/templates/plugins/hello/defaultAction.ts +27 -0
- package/dist/templates/plugins/hello/index.ts +26 -0
- package/dist/templates/plugins/hello/options.ts +31 -0
- package/dist/templates/plugins/hello/strangerAction.ts +20 -0
- package/dist/templates/plugins/hello/types.ts +13 -0
- package/dist/templates/strangerAction.ts +20 -0
- package/dist/templates/types.ts +13 -0
- package/package.json +2 -2
- package/templates/cli/plugins/hello/defaultAction.ts +27 -0
- package/templates/cli/plugins/hello/index.ts +26 -0
- package/templates/cli/plugins/hello/options.ts +31 -0
- package/templates/cli/plugins/hello/strangerAction.ts +20 -0
- package/templates/cli/plugins/hello/types.ts +13 -0
- package/dist/templates/cli/plugins/hello.ts +0 -42
- package/dist/templates/hello.ts +0 -42
- package/dist/templates/plugins/hello.ts +0 -42
- package/templates/cli/plugins/hello.ts +0 -42
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GetDotenvCliPublic,
|
|
3
|
+
getRootCommand,
|
|
4
|
+
} from '@karmaniverous/get-dotenv/cliHost';
|
|
5
|
+
|
|
6
|
+
import type { HelloPlugin } from '.';
|
|
7
|
+
import type { HelloCommand } from './options';
|
|
8
|
+
|
|
9
|
+
export function attachHelloDefaultAction(
|
|
10
|
+
cli: GetDotenvCliPublic,
|
|
11
|
+
cmd: HelloCommand,
|
|
12
|
+
plugin: HelloPlugin,
|
|
13
|
+
) {
|
|
14
|
+
cmd.action((opts) => {
|
|
15
|
+
const ctx = cli.getCtx();
|
|
16
|
+
// Derive CLI name from the true root command using a typed helper.
|
|
17
|
+
const rootName = getRootCommand(cli).name();
|
|
18
|
+
|
|
19
|
+
const cfg = plugin.readConfig(cli);
|
|
20
|
+
const loud =
|
|
21
|
+
opts.loud === true ? true : opts.loudOff === true ? false : cfg.loud;
|
|
22
|
+
|
|
23
|
+
const keys = Object.keys(ctx.dotenv);
|
|
24
|
+
const label = `Hello, stranger!\n\n[${rootName}] dotenv keys (${String(keys.length)}):`;
|
|
25
|
+
console.log(loud ? label.toUpperCase() : label, keys.join(', '));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { definePlugin } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import { attachHelloDefaultAction } from './defaultAction';
|
|
4
|
+
import { attachHelloOptions } from './options';
|
|
5
|
+
import { attachHelloStrangerAction } from './strangerAction';
|
|
6
|
+
import { helloPluginConfigSchema } from './types';
|
|
7
|
+
|
|
8
|
+
export const helloPlugin = () => {
|
|
9
|
+
const plugin = definePlugin({
|
|
10
|
+
ns: 'hello',
|
|
11
|
+
configSchema: helloPluginConfigSchema,
|
|
12
|
+
setup(cli) {
|
|
13
|
+
// Keep description in the plugin “index” (this file), not in an options helper.
|
|
14
|
+
cli.description('Say hello with current dotenv context');
|
|
15
|
+
|
|
16
|
+
const helloCmd = attachHelloOptions(cli, plugin);
|
|
17
|
+
attachHelloDefaultAction(cli, helloCmd, plugin);
|
|
18
|
+
attachHelloStrangerAction(cli);
|
|
19
|
+
|
|
20
|
+
return undefined;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return plugin;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type HelloPlugin = ReturnType<typeof helloPlugin>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import type { HelloPlugin } from '.';
|
|
4
|
+
import type { HelloPluginConfig } from './types';
|
|
5
|
+
|
|
6
|
+
export function attachHelloOptions(
|
|
7
|
+
cli: GetDotenvCliPublic,
|
|
8
|
+
plugin: HelloPlugin,
|
|
9
|
+
) {
|
|
10
|
+
const loudOn = plugin
|
|
11
|
+
.createPluginDynamicOption(
|
|
12
|
+
cli,
|
|
13
|
+
'-l, --loud',
|
|
14
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
15
|
+
`print greeting in ALL CAPS${pluginCfg.loud ? ' (default)' : ''}`,
|
|
16
|
+
)
|
|
17
|
+
.conflicts('loudOff');
|
|
18
|
+
|
|
19
|
+
const loudOff = plugin
|
|
20
|
+
.createPluginDynamicOption(
|
|
21
|
+
cli,
|
|
22
|
+
'-L, --loud-off',
|
|
23
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
24
|
+
`print greeting in normal case${pluginCfg.loud ? '' : ' (default)'}`,
|
|
25
|
+
)
|
|
26
|
+
.conflicts('loud');
|
|
27
|
+
|
|
28
|
+
return cli.addOption(loudOn).addOption(loudOff);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type HelloCommand = ReturnType<typeof attachHelloOptions>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attach the `stranger` subcommand under `hello`.
|
|
5
|
+
*
|
|
6
|
+
* Reads `SECRET_IDENTITY` from the resolved get-dotenv context (`cli.getCtx().dotenv`).
|
|
7
|
+
*
|
|
8
|
+
* @param cli - The `hello` command mount.
|
|
9
|
+
* @returns Nothing.
|
|
10
|
+
*/
|
|
11
|
+
export function attachHelloStrangerAction(cli: GetDotenvCliPublic): void {
|
|
12
|
+
const really = cli
|
|
13
|
+
.ns('stranger')
|
|
14
|
+
.description('Print SECRET_IDENTITY from the resolved dotenv context');
|
|
15
|
+
|
|
16
|
+
really.action(() => {
|
|
17
|
+
const secretIdentity = really.getCtx().dotenv.SECRET_IDENTITY;
|
|
18
|
+
console.log(`My secret identity is ${secretIdentity ?? 'still a secret'}.`);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for hello plugin configuration.
|
|
5
|
+
*/
|
|
6
|
+
export const helloPluginConfigSchema = z.object({
|
|
7
|
+
loud: z.boolean().optional().default(false),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hello plugin configuration object.
|
|
12
|
+
*/
|
|
13
|
+
export type HelloPluginConfig = z.infer<typeof helloPluginConfigSchema>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GetDotenvCliPublic,
|
|
3
|
+
getRootCommand,
|
|
4
|
+
} from '@karmaniverous/get-dotenv/cliHost';
|
|
5
|
+
|
|
6
|
+
import type { HelloPlugin } from '.';
|
|
7
|
+
import type { HelloCommand } from './options';
|
|
8
|
+
|
|
9
|
+
export function attachHelloDefaultAction(
|
|
10
|
+
cli: GetDotenvCliPublic,
|
|
11
|
+
cmd: HelloCommand,
|
|
12
|
+
plugin: HelloPlugin,
|
|
13
|
+
) {
|
|
14
|
+
cmd.action((opts) => {
|
|
15
|
+
const ctx = cli.getCtx();
|
|
16
|
+
// Derive CLI name from the true root command using a typed helper.
|
|
17
|
+
const rootName = getRootCommand(cli).name();
|
|
18
|
+
|
|
19
|
+
const cfg = plugin.readConfig(cli);
|
|
20
|
+
const loud =
|
|
21
|
+
opts.loud === true ? true : opts.loudOff === true ? false : cfg.loud;
|
|
22
|
+
|
|
23
|
+
const keys = Object.keys(ctx.dotenv);
|
|
24
|
+
const label = `Hello, stranger!\n\n[${rootName}] dotenv keys (${String(keys.length)}):`;
|
|
25
|
+
console.log(loud ? label.toUpperCase() : label, keys.join(', '));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GetDotenvCliPublic,
|
|
3
|
+
getRootCommand,
|
|
4
|
+
} from '@karmaniverous/get-dotenv/cliHost';
|
|
5
|
+
|
|
6
|
+
import type { HelloPlugin } from '.';
|
|
7
|
+
import type { HelloCommand } from './options';
|
|
8
|
+
|
|
9
|
+
export function attachHelloDefaultAction(
|
|
10
|
+
cli: GetDotenvCliPublic,
|
|
11
|
+
cmd: HelloCommand,
|
|
12
|
+
plugin: HelloPlugin,
|
|
13
|
+
) {
|
|
14
|
+
cmd.action((opts) => {
|
|
15
|
+
const ctx = cli.getCtx();
|
|
16
|
+
// Derive CLI name from the true root command using a typed helper.
|
|
17
|
+
const rootName = getRootCommand(cli).name();
|
|
18
|
+
|
|
19
|
+
const cfg = plugin.readConfig(cli);
|
|
20
|
+
const loud =
|
|
21
|
+
opts.loud === true ? true : opts.loudOff === true ? false : cfg.loud;
|
|
22
|
+
|
|
23
|
+
const keys = Object.keys(ctx.dotenv);
|
|
24
|
+
const label = `Hello, stranger!\n\n[${rootName}] dotenv keys (${String(keys.length)}):`;
|
|
25
|
+
console.log(loud ? label.toUpperCase() : label, keys.join(', '));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { definePlugin } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import { attachHelloDefaultAction } from './defaultAction';
|
|
4
|
+
import { attachHelloOptions } from './options';
|
|
5
|
+
import { attachHelloStrangerAction } from './strangerAction';
|
|
6
|
+
import { helloPluginConfigSchema } from './types';
|
|
7
|
+
|
|
8
|
+
export const helloPlugin = () => {
|
|
9
|
+
const plugin = definePlugin({
|
|
10
|
+
ns: 'hello',
|
|
11
|
+
configSchema: helloPluginConfigSchema,
|
|
12
|
+
setup(cli) {
|
|
13
|
+
// Keep description in the plugin “index” (this file), not in an options helper.
|
|
14
|
+
cli.description('Say hello with current dotenv context');
|
|
15
|
+
|
|
16
|
+
const helloCmd = attachHelloOptions(cli, plugin);
|
|
17
|
+
attachHelloDefaultAction(cli, helloCmd, plugin);
|
|
18
|
+
attachHelloStrangerAction(cli);
|
|
19
|
+
|
|
20
|
+
return undefined;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return plugin;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type HelloPlugin = ReturnType<typeof helloPlugin>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import type { HelloPlugin } from '.';
|
|
4
|
+
import type { HelloPluginConfig } from './types';
|
|
5
|
+
|
|
6
|
+
export function attachHelloOptions(
|
|
7
|
+
cli: GetDotenvCliPublic,
|
|
8
|
+
plugin: HelloPlugin,
|
|
9
|
+
) {
|
|
10
|
+
const loudOn = plugin
|
|
11
|
+
.createPluginDynamicOption(
|
|
12
|
+
cli,
|
|
13
|
+
'-l, --loud',
|
|
14
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
15
|
+
`print greeting in ALL CAPS${pluginCfg.loud ? ' (default)' : ''}`,
|
|
16
|
+
)
|
|
17
|
+
.conflicts('loudOff');
|
|
18
|
+
|
|
19
|
+
const loudOff = plugin
|
|
20
|
+
.createPluginDynamicOption(
|
|
21
|
+
cli,
|
|
22
|
+
'-L, --loud-off',
|
|
23
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
24
|
+
`print greeting in normal case${pluginCfg.loud ? '' : ' (default)'}`,
|
|
25
|
+
)
|
|
26
|
+
.conflicts('loud');
|
|
27
|
+
|
|
28
|
+
return cli.addOption(loudOn).addOption(loudOff);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type HelloCommand = ReturnType<typeof attachHelloOptions>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attach the `stranger` subcommand under `hello`.
|
|
5
|
+
*
|
|
6
|
+
* Reads `SECRET_IDENTITY` from the resolved get-dotenv context (`cli.getCtx().dotenv`).
|
|
7
|
+
*
|
|
8
|
+
* @param cli - The `hello` command mount.
|
|
9
|
+
* @returns Nothing.
|
|
10
|
+
*/
|
|
11
|
+
export function attachHelloStrangerAction(cli: GetDotenvCliPublic): void {
|
|
12
|
+
const really = cli
|
|
13
|
+
.ns('stranger')
|
|
14
|
+
.description('Print SECRET_IDENTITY from the resolved dotenv context');
|
|
15
|
+
|
|
16
|
+
really.action(() => {
|
|
17
|
+
const secretIdentity = really.getCtx().dotenv.SECRET_IDENTITY;
|
|
18
|
+
console.log(`My secret identity is ${secretIdentity ?? 'still a secret'}.`);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for hello plugin configuration.
|
|
5
|
+
*/
|
|
6
|
+
export const helloPluginConfigSchema = z.object({
|
|
7
|
+
loud: z.boolean().optional().default(false),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hello plugin configuration object.
|
|
12
|
+
*/
|
|
13
|
+
export type HelloPluginConfig = z.infer<typeof helloPluginConfigSchema>;
|
package/dist/templates/index.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
import { definePlugin } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
batchPlugin,
|
|
8
|
-
cmdPlugin,
|
|
9
|
-
initPlugin,
|
|
10
|
-
} from '@karmaniverous/get-dotenv/plugins';
|
|
3
|
+
import { attachHelloDefaultAction } from './defaultAction';
|
|
4
|
+
import { attachHelloOptions } from './options';
|
|
5
|
+
import { attachHelloStrangerAction } from './strangerAction';
|
|
6
|
+
import { helloPluginConfigSchema } from './types';
|
|
11
7
|
|
|
12
|
-
|
|
8
|
+
export const helloPlugin = () => {
|
|
9
|
+
const plugin = definePlugin({
|
|
10
|
+
ns: 'hello',
|
|
11
|
+
configSchema: helloPluginConfigSchema,
|
|
12
|
+
setup(cli) {
|
|
13
|
+
// Keep description in the plugin “index” (this file), not in an options helper.
|
|
14
|
+
cli.description('Say hello with current dotenv context');
|
|
13
15
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
})();
|
|
16
|
+
const helloCmd = attachHelloOptions(cli, plugin);
|
|
17
|
+
attachHelloDefaultAction(cli, helloCmd, plugin);
|
|
18
|
+
attachHelloStrangerAction(cli);
|
|
19
|
+
|
|
20
|
+
return undefined;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return plugin;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type HelloPlugin = ReturnType<typeof helloPlugin>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import type { HelloPlugin } from '.';
|
|
4
|
+
import type { HelloPluginConfig } from './types';
|
|
5
|
+
|
|
6
|
+
export function attachHelloOptions(
|
|
7
|
+
cli: GetDotenvCliPublic,
|
|
8
|
+
plugin: HelloPlugin,
|
|
9
|
+
) {
|
|
10
|
+
const loudOn = plugin
|
|
11
|
+
.createPluginDynamicOption(
|
|
12
|
+
cli,
|
|
13
|
+
'-l, --loud',
|
|
14
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
15
|
+
`print greeting in ALL CAPS${pluginCfg.loud ? ' (default)' : ''}`,
|
|
16
|
+
)
|
|
17
|
+
.conflicts('loudOff');
|
|
18
|
+
|
|
19
|
+
const loudOff = plugin
|
|
20
|
+
.createPluginDynamicOption(
|
|
21
|
+
cli,
|
|
22
|
+
'-L, --loud-off',
|
|
23
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
24
|
+
`print greeting in normal case${pluginCfg.loud ? '' : ' (default)'}`,
|
|
25
|
+
)
|
|
26
|
+
.conflicts('loud');
|
|
27
|
+
|
|
28
|
+
return cli.addOption(loudOn).addOption(loudOff);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type HelloCommand = ReturnType<typeof attachHelloOptions>;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GetDotenvCliPublic,
|
|
3
|
+
getRootCommand,
|
|
4
|
+
} from '@karmaniverous/get-dotenv/cliHost';
|
|
5
|
+
|
|
6
|
+
import type { HelloPlugin } from '.';
|
|
7
|
+
import type { HelloCommand } from './options';
|
|
8
|
+
|
|
9
|
+
export function attachHelloDefaultAction(
|
|
10
|
+
cli: GetDotenvCliPublic,
|
|
11
|
+
cmd: HelloCommand,
|
|
12
|
+
plugin: HelloPlugin,
|
|
13
|
+
) {
|
|
14
|
+
cmd.action((opts) => {
|
|
15
|
+
const ctx = cli.getCtx();
|
|
16
|
+
// Derive CLI name from the true root command using a typed helper.
|
|
17
|
+
const rootName = getRootCommand(cli).name();
|
|
18
|
+
|
|
19
|
+
const cfg = plugin.readConfig(cli);
|
|
20
|
+
const loud =
|
|
21
|
+
opts.loud === true ? true : opts.loudOff === true ? false : cfg.loud;
|
|
22
|
+
|
|
23
|
+
const keys = Object.keys(ctx.dotenv);
|
|
24
|
+
const label = `Hello, stranger!\n\n[${rootName}] dotenv keys (${String(keys.length)}):`;
|
|
25
|
+
console.log(loud ? label.toUpperCase() : label, keys.join(', '));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { definePlugin } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import { attachHelloDefaultAction } from './defaultAction';
|
|
4
|
+
import { attachHelloOptions } from './options';
|
|
5
|
+
import { attachHelloStrangerAction } from './strangerAction';
|
|
6
|
+
import { helloPluginConfigSchema } from './types';
|
|
7
|
+
|
|
8
|
+
export const helloPlugin = () => {
|
|
9
|
+
const plugin = definePlugin({
|
|
10
|
+
ns: 'hello',
|
|
11
|
+
configSchema: helloPluginConfigSchema,
|
|
12
|
+
setup(cli) {
|
|
13
|
+
// Keep description in the plugin “index” (this file), not in an options helper.
|
|
14
|
+
cli.description('Say hello with current dotenv context');
|
|
15
|
+
|
|
16
|
+
const helloCmd = attachHelloOptions(cli, plugin);
|
|
17
|
+
attachHelloDefaultAction(cli, helloCmd, plugin);
|
|
18
|
+
attachHelloStrangerAction(cli);
|
|
19
|
+
|
|
20
|
+
return undefined;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return plugin;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type HelloPlugin = ReturnType<typeof helloPlugin>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import type { HelloPlugin } from '.';
|
|
4
|
+
import type { HelloPluginConfig } from './types';
|
|
5
|
+
|
|
6
|
+
export function attachHelloOptions(
|
|
7
|
+
cli: GetDotenvCliPublic,
|
|
8
|
+
plugin: HelloPlugin,
|
|
9
|
+
) {
|
|
10
|
+
const loudOn = plugin
|
|
11
|
+
.createPluginDynamicOption(
|
|
12
|
+
cli,
|
|
13
|
+
'-l, --loud',
|
|
14
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
15
|
+
`print greeting in ALL CAPS${pluginCfg.loud ? ' (default)' : ''}`,
|
|
16
|
+
)
|
|
17
|
+
.conflicts('loudOff');
|
|
18
|
+
|
|
19
|
+
const loudOff = plugin
|
|
20
|
+
.createPluginDynamicOption(
|
|
21
|
+
cli,
|
|
22
|
+
'-L, --loud-off',
|
|
23
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
24
|
+
`print greeting in normal case${pluginCfg.loud ? '' : ' (default)'}`,
|
|
25
|
+
)
|
|
26
|
+
.conflicts('loud');
|
|
27
|
+
|
|
28
|
+
return cli.addOption(loudOn).addOption(loudOff);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type HelloCommand = ReturnType<typeof attachHelloOptions>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attach the `stranger` subcommand under `hello`.
|
|
5
|
+
*
|
|
6
|
+
* Reads `SECRET_IDENTITY` from the resolved get-dotenv context (`cli.getCtx().dotenv`).
|
|
7
|
+
*
|
|
8
|
+
* @param cli - The `hello` command mount.
|
|
9
|
+
* @returns Nothing.
|
|
10
|
+
*/
|
|
11
|
+
export function attachHelloStrangerAction(cli: GetDotenvCliPublic): void {
|
|
12
|
+
const really = cli
|
|
13
|
+
.ns('stranger')
|
|
14
|
+
.description('Print SECRET_IDENTITY from the resolved dotenv context');
|
|
15
|
+
|
|
16
|
+
really.action(() => {
|
|
17
|
+
const secretIdentity = really.getCtx().dotenv.SECRET_IDENTITY;
|
|
18
|
+
console.log(`My secret identity is ${secretIdentity ?? 'still a secret'}.`);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for hello plugin configuration.
|
|
5
|
+
*/
|
|
6
|
+
export const helloPluginConfigSchema = z.object({
|
|
7
|
+
loud: z.boolean().optional().default(false),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hello plugin configuration object.
|
|
12
|
+
*/
|
|
13
|
+
export type HelloPluginConfig = z.infer<typeof helloPluginConfigSchema>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attach the `stranger` subcommand under `hello`.
|
|
5
|
+
*
|
|
6
|
+
* Reads `SECRET_IDENTITY` from the resolved get-dotenv context (`cli.getCtx().dotenv`).
|
|
7
|
+
*
|
|
8
|
+
* @param cli - The `hello` command mount.
|
|
9
|
+
* @returns Nothing.
|
|
10
|
+
*/
|
|
11
|
+
export function attachHelloStrangerAction(cli: GetDotenvCliPublic): void {
|
|
12
|
+
const really = cli
|
|
13
|
+
.ns('stranger')
|
|
14
|
+
.description('Print SECRET_IDENTITY from the resolved dotenv context');
|
|
15
|
+
|
|
16
|
+
really.action(() => {
|
|
17
|
+
const secretIdentity = really.getCtx().dotenv.SECRET_IDENTITY;
|
|
18
|
+
console.log(`My secret identity is ${secretIdentity ?? 'still a secret'}.`);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for hello plugin configuration.
|
|
5
|
+
*/
|
|
6
|
+
export const helloPluginConfigSchema = z.object({
|
|
7
|
+
loud: z.boolean().optional().default(false),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hello plugin configuration object.
|
|
12
|
+
*/
|
|
13
|
+
export type HelloPluginConfig = z.infer<typeof helloPluginConfigSchema>;
|
package/package.json
CHANGED
|
@@ -213,7 +213,7 @@
|
|
|
213
213
|
"release": "dotenvx run -f .env.local -- release-it",
|
|
214
214
|
"release:pre": "dotenvx run -f .env.local -- release-it --no-git.requireBranch --github.prerelease --preRelease",
|
|
215
215
|
"test": "vitest run",
|
|
216
|
-
"typecheck": "tsc
|
|
216
|
+
"typecheck": "tsc",
|
|
217
217
|
"verify:types": "node tools/verify-types.js",
|
|
218
218
|
"verify:package": "node tools/verify-package.js",
|
|
219
219
|
"verify:smoke": "node tools/smoke.js",
|
|
@@ -222,5 +222,5 @@
|
|
|
222
222
|
},
|
|
223
223
|
"type": "module",
|
|
224
224
|
"types": "dist/index.d.ts",
|
|
225
|
-
"version": "6.1.
|
|
225
|
+
"version": "6.1.1"
|
|
226
226
|
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import {
|
|
2
|
+
type GetDotenvCliPublic,
|
|
3
|
+
getRootCommand,
|
|
4
|
+
} from '@karmaniverous/get-dotenv/cliHost';
|
|
5
|
+
|
|
6
|
+
import type { HelloPlugin } from '.';
|
|
7
|
+
import type { HelloCommand } from './options';
|
|
8
|
+
|
|
9
|
+
export function attachHelloDefaultAction(
|
|
10
|
+
cli: GetDotenvCliPublic,
|
|
11
|
+
cmd: HelloCommand,
|
|
12
|
+
plugin: HelloPlugin,
|
|
13
|
+
) {
|
|
14
|
+
cmd.action((opts) => {
|
|
15
|
+
const ctx = cli.getCtx();
|
|
16
|
+
// Derive CLI name from the true root command using a typed helper.
|
|
17
|
+
const rootName = getRootCommand(cli).name();
|
|
18
|
+
|
|
19
|
+
const cfg = plugin.readConfig(cli);
|
|
20
|
+
const loud =
|
|
21
|
+
opts.loud === true ? true : opts.loudOff === true ? false : cfg.loud;
|
|
22
|
+
|
|
23
|
+
const keys = Object.keys(ctx.dotenv);
|
|
24
|
+
const label = `Hello, stranger!\n\n[${rootName}] dotenv keys (${String(keys.length)}):`;
|
|
25
|
+
console.log(loud ? label.toUpperCase() : label, keys.join(', '));
|
|
26
|
+
});
|
|
27
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { definePlugin } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import { attachHelloDefaultAction } from './defaultAction';
|
|
4
|
+
import { attachHelloOptions } from './options';
|
|
5
|
+
import { attachHelloStrangerAction } from './strangerAction';
|
|
6
|
+
import { helloPluginConfigSchema } from './types';
|
|
7
|
+
|
|
8
|
+
export const helloPlugin = () => {
|
|
9
|
+
const plugin = definePlugin({
|
|
10
|
+
ns: 'hello',
|
|
11
|
+
configSchema: helloPluginConfigSchema,
|
|
12
|
+
setup(cli) {
|
|
13
|
+
// Keep description in the plugin “index” (this file), not in an options helper.
|
|
14
|
+
cli.description('Say hello with current dotenv context');
|
|
15
|
+
|
|
16
|
+
const helloCmd = attachHelloOptions(cli, plugin);
|
|
17
|
+
attachHelloDefaultAction(cli, helloCmd, plugin);
|
|
18
|
+
attachHelloStrangerAction(cli);
|
|
19
|
+
|
|
20
|
+
return undefined;
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
return plugin;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type HelloPlugin = ReturnType<typeof helloPlugin>;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
import type { HelloPlugin } from '.';
|
|
4
|
+
import type { HelloPluginConfig } from './types';
|
|
5
|
+
|
|
6
|
+
export function attachHelloOptions(
|
|
7
|
+
cli: GetDotenvCliPublic,
|
|
8
|
+
plugin: HelloPlugin,
|
|
9
|
+
) {
|
|
10
|
+
const loudOn = plugin
|
|
11
|
+
.createPluginDynamicOption(
|
|
12
|
+
cli,
|
|
13
|
+
'-l, --loud',
|
|
14
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
15
|
+
`print greeting in ALL CAPS${pluginCfg.loud ? ' (default)' : ''}`,
|
|
16
|
+
)
|
|
17
|
+
.conflicts('loudOff');
|
|
18
|
+
|
|
19
|
+
const loudOff = plugin
|
|
20
|
+
.createPluginDynamicOption(
|
|
21
|
+
cli,
|
|
22
|
+
'-L, --loud-off',
|
|
23
|
+
(_bag, pluginCfg: Readonly<HelloPluginConfig>) =>
|
|
24
|
+
`print greeting in normal case${pluginCfg.loud ? '' : ' (default)'}`,
|
|
25
|
+
)
|
|
26
|
+
.conflicts('loud');
|
|
27
|
+
|
|
28
|
+
return cli.addOption(loudOn).addOption(loudOff);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export type HelloCommand = ReturnType<typeof attachHelloOptions>;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GetDotenvCliPublic } from '@karmaniverous/get-dotenv/cliHost';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Attach the `stranger` subcommand under `hello`.
|
|
5
|
+
*
|
|
6
|
+
* Reads `SECRET_IDENTITY` from the resolved get-dotenv context (`cli.getCtx().dotenv`).
|
|
7
|
+
*
|
|
8
|
+
* @param cli - The `hello` command mount.
|
|
9
|
+
* @returns Nothing.
|
|
10
|
+
*/
|
|
11
|
+
export function attachHelloStrangerAction(cli: GetDotenvCliPublic): void {
|
|
12
|
+
const really = cli
|
|
13
|
+
.ns('stranger')
|
|
14
|
+
.description('Print SECRET_IDENTITY from the resolved dotenv context');
|
|
15
|
+
|
|
16
|
+
really.action(() => {
|
|
17
|
+
const secretIdentity = really.getCtx().dotenv.SECRET_IDENTITY;
|
|
18
|
+
console.log(`My secret identity is ${secretIdentity ?? 'still a secret'}.`);
|
|
19
|
+
});
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Zod schema for hello plugin configuration.
|
|
5
|
+
*/
|
|
6
|
+
export const helloPluginConfigSchema = z.object({
|
|
7
|
+
loud: z.boolean().optional().default(false),
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Hello plugin configuration object.
|
|
12
|
+
*/
|
|
13
|
+
export type HelloPluginConfig = z.infer<typeof helloPluginConfigSchema>;
|