[docs] setup flake and dir
This commit is contained in:
95
cmd/docbuilder/docbuilder.go
Normal file
95
cmd/docbuilder/docbuilder.go
Normal file
@@ -0,0 +1,95 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
"os"
|
||||
"flag"
|
||||
|
||||
"unknown.com/gokill/actions"
|
||||
"unknown.com/gokill/triggers"
|
||||
"unknown.com/gokill/internal"
|
||||
)
|
||||
|
||||
func getMarkdown(documenter internal.Documenter) string {
|
||||
var result string
|
||||
result += fmt.Sprintf("# %v\n**%v**\n\nValues:\n", documenter.GetName(), documenter.GetDescription())
|
||||
|
||||
for _, opt := range documenter.GetOptions() {
|
||||
result += fmt.Sprintf("- Name: **%v**\n\t- Type: %v\n\t- Descr: %v\n\t- Default: %v\n",
|
||||
opt.Name, opt.Type, opt.Description, opt.Default)
|
||||
result += "\n\n"
|
||||
}
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
func writeToFile(path string, documenter internal.Documenter) error {
|
||||
fileName := fmt.Sprintf("%s/%s.md", path, documenter.GetName())
|
||||
|
||||
f, err := os.Create(fileName)
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
defer f.Close()
|
||||
|
||||
_, err = f.WriteString(getMarkdown(documenter))
|
||||
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func writeDocumentersToFiles(destination string) {
|
||||
writeFolder := func(typeName string, documenters []internal.Documenter) {
|
||||
path := fmt.Sprintf("%s/%s", destination, typeName)
|
||||
_ = os.Mkdir(path, os.ModePerm)
|
||||
for _, documenter := range documenters {
|
||||
writeToFile(path, documenter)
|
||||
}
|
||||
}
|
||||
|
||||
actions := actions.GetDocumenters()
|
||||
writeFolder("actions", actions)
|
||||
|
||||
triggers := triggers.GetDocumenters()
|
||||
writeFolder("triggers", triggers)
|
||||
}
|
||||
|
||||
func printDocumentersSummary() {
|
||||
result := fmt.Sprintf("- [Triggers](triggers/README.md)\n")
|
||||
for _, trigger := range triggers.GetDocumenters() {
|
||||
result += fmt.Sprintf("\t- [%s](triggers/%s.md)\n", trigger.GetName(), trigger.GetName())
|
||||
}
|
||||
|
||||
result += fmt.Sprintf("- [Actions](actions/README.md)\n")
|
||||
for _, action := range actions.GetDocumenters() {
|
||||
result += fmt.Sprintf("\t- [%s](actions/%s.md)\n", action.GetName(), action.GetName())
|
||||
}
|
||||
|
||||
fmt.Print(result)
|
||||
}
|
||||
|
||||
|
||||
func main() {
|
||||
outputPath := flag.String("output", "", "path where docs/ shoud be created")
|
||||
|
||||
flag.Parse()
|
||||
|
||||
if *outputPath == "" {
|
||||
printDocumentersSummary()
|
||||
return
|
||||
}
|
||||
|
||||
if len(*outputPath) > 1 {
|
||||
*outputPath = strings.TrimSuffix(*outputPath, "/")
|
||||
}
|
||||
|
||||
writeDocumentersToFiles(*outputPath)
|
||||
}
|
||||
@@ -1,7 +1,4 @@
|
||||
# Summary
|
||||
|
||||
- [Introduction](./gokill.md)
|
||||
- [Triggers](triggers/triggers.md)
|
||||
- [Timeout](triggers/timeout.md)
|
||||
- [EthernetDisconnect](triggers/ethernetdisconnect.md)
|
||||
- [Actions](actions/actions.md)
|
||||
@GOKILL_OPTIONS@
|
||||
|
||||
1
docs/actions/README.md
Normal file
1
docs/actions/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# Actions
|
||||
@@ -1,34 +0,0 @@
|
||||
# Available Actions:
|
||||
|
||||
# Print
|
||||
Description: When triggered prints the configured message to stdout
|
||||
Values:
|
||||
- **message**
|
||||
- Type: string
|
||||
- Descr: Message that should be printed
|
||||
- Default: ""
|
||||
|
||||
### Timeout
|
||||
Description: When triggered waits given duration before continuing with next stage
|
||||
Values:
|
||||
- **duration**
|
||||
- Type: int
|
||||
- Descr: duration in seconds
|
||||
- Default: 0
|
||||
|
||||
# Command
|
||||
Description: When triggered executes given command
|
||||
Values:
|
||||
- **command**
|
||||
- Type: string
|
||||
- Descr: command to execute
|
||||
- Default:
|
||||
- **args**
|
||||
- Type: string[]
|
||||
- Descr: args
|
||||
- Default:
|
||||
|
||||
### Shutdown
|
||||
Description: When triggered shuts down the machine
|
||||
Values:
|
||||
|
||||
32
docs/default.nix
Normal file
32
docs/default.nix
Normal file
@@ -0,0 +1,32 @@
|
||||
{ pkgs, lib, self, ... }:
|
||||
|
||||
with lib;
|
||||
let
|
||||
docbuilder = self.packages.x86_64-linux.gokill-docbuilder;
|
||||
|
||||
prepareMD = ''
|
||||
# Copy inputs into the build directory
|
||||
cp -r --no-preserve=all $inputs/* ./
|
||||
|
||||
${docbuilder}/bin/docbuilder --output ./
|
||||
substituteInPlace ./SUMMARY.md \
|
||||
--replace "@GOKILL_OPTIONS@" "$(${docbuilder}/bin/docbuilder)"
|
||||
|
||||
cat ./SUMMARY.md
|
||||
'';
|
||||
in
|
||||
pkgs.stdenv.mkDerivation {
|
||||
name = "gokill-docs";
|
||||
phases = [ "buildPhase" ];
|
||||
buildInputs = [ pkgs.mdbook ];
|
||||
|
||||
inputs = sourceFilesBySuffices ./. [ ".md" ".toml" ];
|
||||
|
||||
buildPhase = ''
|
||||
dest=$out/share/doc
|
||||
mkdir -p $dest
|
||||
${prepareMD}
|
||||
mdbook build
|
||||
cp -r ./book/* $dest
|
||||
'';
|
||||
}
|
||||
1
docs/triggers/README.md
Normal file
1
docs/triggers/README.md
Normal file
@@ -0,0 +1 @@
|
||||
# Triggers
|
||||
@@ -1,12 +0,0 @@
|
||||
# EthernetDisconnect
|
||||
Description: Triggers if Ethernetcable is disconnected.
|
||||
Values:
|
||||
- **waitTillConnected**
|
||||
- Type: bool
|
||||
- Descr: Only trigger when device was connected before
|
||||
- Default: true
|
||||
- **interfaceName**
|
||||
- Type: string
|
||||
- Descr: Name of ethernet adapter
|
||||
- Default: ""
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
# Timeout
|
||||
|
||||
Description: Triggers after given duration.
|
||||
Values:
|
||||
- **duration**
|
||||
- Type: int
|
||||
- Descr: duration in seconds
|
||||
- Default: 0
|
||||
|
||||
@@ -1,16 +0,0 @@
|
||||
# Available Triggers:
|
||||
|
||||
|
||||
### UsbDisconnect
|
||||
Description: Triggers when given usb drive is disconnected
|
||||
Values:
|
||||
- **waitTillConnected**
|
||||
- Type: bool
|
||||
- Descr: Only trigger when device was connected before
|
||||
- Default: true
|
||||
- **deviceId**
|
||||
- Type: string
|
||||
- Descr: Name of device under /dev/disk/by-id/
|
||||
- Default: ""
|
||||
|
||||
|
||||
20
flake.nix
20
flake.nix
@@ -28,6 +28,20 @@
|
||||
'';
|
||||
};
|
||||
|
||||
packages.x86_64-linux.gokill-docbuilder = nixpkgs.legacyPackages.x86_64-linux.buildGoModule rec {
|
||||
pname = "docbuilder";
|
||||
version = "1.0";
|
||||
vendorHash = null;
|
||||
buildFLags = "-o . $dest/cmd/gokill/docbuilder";
|
||||
src = ./.;
|
||||
|
||||
postInstall = ''
|
||||
'';
|
||||
};
|
||||
|
||||
|
||||
packages.x86_64-linux.docs = pkgs.callPackage (import ./docs/default.nix) { self = self; };
|
||||
|
||||
packages.x86_64-linux.default = self.packages.x86_64-linux.gokill;
|
||||
|
||||
nixosModules.gokill = { config, lib, pkgs, ... }:
|
||||
@@ -140,5 +154,11 @@
|
||||
${self.packages."x86_64-linux".testVm}/bin/run-nixos-vm
|
||||
'');
|
||||
};
|
||||
|
||||
apps.x86_64-linux.docs = {
|
||||
type = "app";
|
||||
program = builtins.toString (nixpkgs.legacyPackages."x86_64-linux".writeScript "docs" ''
|
||||
${pkgs.python3}/bin/python3 -m http.server --directory ${self.packages."x86_64-linux".docs}/share/doc'');
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user