Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable file output modes for docs and example #11

Merged
merged 2 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 15 additions & 12 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,26 @@
# This file is used to store environment variables for the application
# It is not meant to be checked into version control

# Section
# Another section
#
# Description of REQUIRED_VARIABLE
REQUIRED_VARIABLE=
# REQUIRED_VARIABLE=EXAMPLE_VALUE_1
# REQUIRED_VARIABLE=EXAMPLE_VALUE_2
# REQUIRED_VARIABLE_FILE=/run/secrets/required_variable
# Description of OPTIONAL_VARIABLE_WITH_DEFAULT
# OPTIONAL_VARIABLE_WITH_DEFAULT=EXAMPLE_VALUE_1
# OPTIONAL_VARIABLE_WITH_DEFAULT=EXAMPLE_VALUE_2
#
# OPTIONAL_VARIABLE_WITH_DEFAULT_FILE=/run/secrets/optional_variable_with_default

# Section
#
# Description of OPTIONAL_VARIABLE
# OPTIONAL_VARIABLE=
# OPTIONAL_VARIABLE=EXAMPLE_VALUE_1
# OPTIONAL_VARIABLE=EXAMPLE_VALUE_2
#
# OPTIONAL_VARIABLE_FILE=/run/secrets/optional_variable

# Another section
#
# Description of OPTIONAL_VARIABLE_WITH_DEFAULT
# OPTIONAL_VARIABLE_WITH_DEFAULT=EXAMPLE_VALUE_1
# OPTIONAL_VARIABLE_WITH_DEFAULT=EXAMPLE_VALUE_2
# OPTIONAL_VARIABLE_WITH_DEFAULT_FILE=/run/secrets/optional_variable_with_default
# Description of REQUIRED_VARIABLE
REQUIRED_VARIABLE=
# REQUIRED_VARIABLE=EXAMPLE_VALUE_1
# REQUIRED_VARIABLE=EXAMPLE_VALUE_2
#
# REQUIRED_VARIABLE_FILE=/run/secrets/required_variable
42 changes: 28 additions & 14 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,47 @@ if (import.meta.main) {
const docs = new Command()
.arguments("<path:file>")
.description("Generate documentation from .env files")
.action(async (_options, path: string) => {
console.log(
await parseAndConvert(
path,
new DocsWriter(),
),
.option("-o, --output <path:string>", "Output file path")
.action(async ({ output }, path) => {
const markdown = await parseAndConvert(
path,
new DocsWriter(),
);
if (output) {
await Deno.writeTextFile(output, markdown);
console.log(`File written: ${output}`);
} else {
console.log(markdown);
}
});

const envExample = new Command()
.arguments("<path:string>")
.description("Generate example .env file")
.action(async (_options, path: string) => {
console.log(
await parseAndConvert(
path,
new EnvExampleWriter(),
),
.option("-r, --replace", "Replace existing .env file")
.option("-o, --output <path:string>", "Output file path")
.action(async ({ replace, output }, path: string) => {
const fileContents = await parseAndConvert(
path,
new EnvExampleWriter(),
);
if (replace || output) {
await Deno.writeTextFile(output ?? path, fileContents);
console.log(`File written: ${path}`);
pklaschka marked this conversation as resolved.
Show resolved Hide resolved
} else {
console.log(fileContents);
}
});

await new Command()
.name("envardoc")
.version(metadata.version)
.description(metadata.description)
.meta('Deno', Deno.version.deno)
.meta('FS Read Permissions', Deno.permissions.querySync({ name: "read" }).state)
.meta("Deno", Deno.version.deno)
.meta(
"FS Read Permissions",
Deno.permissions.querySync({ name: "read" }).state,
)
.command("docs", docs)
.command("example", envExample)
.parse(Deno.args);
Expand Down
Loading