diff options
| author | James Elliott <james-d-elliott@users.noreply.github.com> | 2024-06-22 12:15:15 +1000 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-06-22 12:15:15 +1000 | 
| commit | 5a22d8dba69e2f06837a41f512f02b3d57907815 (patch) | |
| tree | 542f20e90485520e4982a33edcf072dc1ba4c48f /cmd/authelia-gen | |
| parent | e307d87afb861674bc54e8a1199ace86c19ba4ac (diff) | |
docs: adjust adr add logic (#7451)
Signed-off-by: James Elliott <james-d-elliott@users.noreply.github.com>
Diffstat (limited to 'cmd/authelia-gen')
| -rw-r--r-- | cmd/authelia-gen/cmd_adr.go | 22 | ||||
| -rw-r--r-- | cmd/authelia-gen/templates/docs-architectural_design_record.md.tmpl | 11 | 
2 files changed, 31 insertions, 2 deletions
diff --git a/cmd/authelia-gen/cmd_adr.go b/cmd/authelia-gen/cmd_adr.go index 46ff130f0..5ecf3de06 100644 --- a/cmd/authelia-gen/cmd_adr.go +++ b/cmd/authelia-gen/cmd_adr.go @@ -4,6 +4,7 @@ import (  	"encoding/json"  	"fmt"  	"os" +	"os/exec"  	"path/filepath"  	"time" @@ -38,10 +39,12 @@ func newADRAddCmd() *cobra.Command {  	cmd.Flags().String("proposed-design", "", "sets the proposed design of the record")  	cmd.Flags().String("decision", "", "sets the decision of the record")  	cmd.Flags().String("consequences", "", "sets the consequences of the record") +	cmd.Flags().IntSlice("related-adrs", nil, "sets the related adrs of the record")  	return cmd  } +//nolint:gocyclo  func adrAddRunE(cmd *cobra.Command, args []string) (err error) {  	var adrs string @@ -95,9 +98,21 @@ func adrAddRunE(cmd *cobra.Command, args []string) (err error) {  		return err  	} +	if data.RelatedADRs, err = cmd.Flags().GetIntSlice("related-adrs"); err != nil { +		return err +	} + +	for _, related := range data.RelatedADRs { +		if related >= config.NextID { +			return fmt.Errorf("related adr %d does not exist yet", related) +		} +	} + +	fp := filepath.Join(adrs, fmt.Sprintf("%d.md", data.ADR)) +  	var f *os.File -	if f, err = os.Create(filepath.Join(adrs, fmt.Sprintf("%d.md", data.ADR))); err != nil { +	if f, err = os.Create(fp); err != nil {  		return fmt.Errorf("error opening file for adr: %w", err)  	} @@ -117,7 +132,9 @@ func adrAddRunE(cmd *cobra.Command, args []string) (err error) {  		return fmt.Errorf("error writing config: %w", err)  	} -	return nil +	gitadd := exec.Command("git", "add", fp) + +	return gitadd.Run()  }  type ArchitectureDesignRecordConfig struct { @@ -136,4 +153,5 @@ type ArchitectureDesignRecordTmpl struct {  	ProposedDesign string  	Decision       string  	Consequences   string +	RelatedADRs    []int  } diff --git a/cmd/authelia-gen/templates/docs-architectural_design_record.md.tmpl b/cmd/authelia-gen/templates/docs-architectural_design_record.md.tmpl index 519b79eee..8b75c67bb 100644 --- a/cmd/authelia-gen/templates/docs-architectural_design_record.md.tmpl +++ b/cmd/authelia-gen/templates/docs-architectural_design_record.md.tmpl @@ -42,3 +42,14 @@ Date: {{ .DateHuman }}  ## Consequences  {{ .Consequences | default "_N/A_" }} + +## Related ADRs + +{{- if .RelatedADRs }} +{{ range .RelatedADRs }} +- [ADR{{ . }}]({{ . }}.md) +{{- end }} +{{- else }} + +_N/A_ +{{- end }}  | 
