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

docs: generate mdbook docs #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
35 changes: 35 additions & 0 deletions docs/book.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{ pkgs, ...}:
let
author = "nixosbrasil";
edit-path = "${org-url}/${project}/edit/master/docs/{path}";
org-url = "https://github.com/${author}";
project = "climod";

# Workaroud to fix infinity recursion
fake-mod = pkgs.writeText "climodmod.nix"
(builtins.replaceStrings
[" options = command;"]
[''options.name = mkOption { type = str; default = "..."; description = "This is a recursive from command"; };'']
(builtins.readFile ../modules/common.nix));
in
{
files.mdbook.authors = ["NixOS Brasil <${org-url}>"];
files.mdbook.enable = true;
files.mdbook.gh-author = author;
files.mdbook.gh-project = project;
files.mdbook.language = "en";
files.mdbook.multilingual = false;
files.mdbook.summary = builtins.readFile ./summary.md;
files.mdbook.title = "Modular Generated Command Line Interfaces";
files.mdbook.output.html.fold.enable = true;
files.mdbook.output.html.edit-url-template = edit-path;
files.mdbook.output.html.git-repository-icon = "fa-github";
files.mdbook.output.html.git-repository-url = "${org-url}/${project}";
files.mdbook.output.html.no-section-label = true;
files.mdbook.output.html.site-url = "/${project}/";
files.text."/gh-pages/src/about.md" = builtins.readFile ../README.md;
files.docs."/gh-pages/src/options.md".modules = [
"${fake-mod}"
../modules/bash/default.nix
];
}
25 changes: 25 additions & 0 deletions docs/options.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{ pkgs, ...}:
let
url = "https://github.com/nixosbrasil/climod";
src = builtins.fetchGit {
inherit url;
rev = "b756461071cbbb105e7913e743795c09337e45b6";
ref = "master";
};
pkg = pkgs.writeText "climodmod.nix"
(builtins.replaceStrings
[" options = command;"]
[''options.name = mkOption { type = str; default = "..."; description = "This is a recursive from command"; };'']
(builtins.readFile "${src}/modules/common.nix"));
in
{
files.docs."/docs/src/climod.md".modules = [
"${pkg}"
"${src}/modules/bash/default.nix"
];
files.mdbook.summary = ''
---
- [Climod](./climod.md)
'';
about.sources = "- [Climod](${url})";
}
4 changes: 4 additions & 0 deletions docs/summary.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Summary

- [About](./about.md)
- [Usage](./options.md)
90 changes: 90 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
description = "Dev Environment";

inputs.nixpkgs.url = "github:nixos/nixpkgs/22.05";
inputs.dsf.url = "github:cruel-intentions/devshell-files";
inputs.dsf.inputs.nixpkgs.follows = "nixpkgs";

outputs = inputs: inputs.dsf.lib.shell inputs [
./docs/book.nix
];
}
16 changes: 16 additions & 0 deletions gh-pages/mdbook.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[book]
authors = ["NixOS Brasil <https://github.com/nixosbrasil>"]
language = "en"
title = "Modular Generated Command Line Interfaces"

[output]

[output.html]
edit-url-template = "https://github.com/nixosbrasil/climod/edit/master/docs/{path}"
git-repository-icon = "fa-github"
git-repository-url = "https://github.com/nixosbrasil/climod"
no-section-label = true
site-url = "/climod/"

[output.html.fold]
enable = true
4 changes: 4 additions & 0 deletions gh-pages/src/SUMMARY.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Summary

- [About](./about.md)
- [Usage](./options.md)
25 changes: 25 additions & 0 deletions gh-pages/src/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# climod

[![built with nix](https://builtwithnix.org/badge.svg)](https://builtwithnix.org)

Modular generated command line interfaces using the same technology as the NixOS module system.

## Objective
What if you could generate CLI scripts with keyword parsing and environment variables with value validation and so on using a JSON like interface, but turing complete...

Or even generate consistent CLIs for more than one programming language... (WIP, only bash atm).

Maybe integrate in your own repo or automations.

With this library and Nix now you can. See the [example](./example.nix) to get more details about how. If you nix-build it then it should generate a script on ./result that you can play with.


# What works
- Generation of bash scripts
- Flag parsing
- Subcommands
- Prelude (setup code before anything but `set -eu` and shebang)
- Your payload code just consume environment variables
- Positional arguments. All input values are flag based so far.
# What doesn't work
- List of things. Each flag can only be provided once.
Loading