Skip to content

Commit efe7541

Browse files
committed
skip README.md generation in extension-init command if it exists
1 parent 84dae7b commit efe7541

File tree

4 files changed

+11
-48
lines changed

4 files changed

+11
-48
lines changed

caddy/extinit.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,11 @@ import (
1414
func init() {
1515
caddycmd.RegisterCommand(caddycmd.Command{
1616
Name: "extension-init",
17-
Usage: "go_extension.go [--overwrite-readme]",
17+
Usage: "go_extension.go",
1818
Short: "Initializes a PHP extension from a Go file (EXPERIMENTAL)",
1919
Long: `
2020
Initializes a PHP extension from a Go file. This command generates the necessary C files for the extension, including the header and source files, as well as the arginfo file.`,
2121
CobraFunc: func(cmd *cobra.Command) {
22-
cmd.Flags().BoolP("overwrite-readme", "r", false, "Overwrite README.md if it exists")
23-
2422
cmd.RunE = cmdInitExtension
2523
},
2624
})
@@ -31,15 +29,10 @@ func cmdInitExtension(cmd *cobra.Command, args []string) error {
3129
return errors.New("the path to the Go source is required")
3230
}
3331

34-
overwriteReadme, err := cmd.Flags().GetBool("overwrite-readme")
35-
if err != nil {
36-
return err
37-
}
38-
3932
sourceFile := args[0]
4033
baseName := extgen.SanitizePackageName(strings.TrimSuffix(filepath.Base(sourceFile), ".go"))
4134

42-
generator := extgen.Generator{BaseName: baseName, SourceFile: sourceFile, BuildDir: filepath.Dir(sourceFile), OverwriteReadme: overwriteReadme}
35+
generator := extgen.Generator{BaseName: baseName, SourceFile: sourceFile, BuildDir: filepath.Dir(sourceFile)}
4336

4437
if err := generator.Generate(); err != nil {
4538
return err

internal/extgen/docs.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ var docFileContent string
1313

1414
type DocumentationGenerator struct {
1515
generator *Generator
16-
overwrite bool
1716
}
1817

1918
type DocTemplateData struct {
@@ -25,7 +24,7 @@ type DocTemplateData struct {
2524
func (dg *DocumentationGenerator) generate() error {
2625
filename := filepath.Join(dg.generator.BuildDir, "README.md")
2726

28-
if _, err := os.Stat(filename); err == nil && !dg.overwrite {
27+
if _, err := os.Stat(filename); err == nil {
2928
return nil
3029
}
3130

internal/extgen/docs_test.go

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ func BenchmarkDocumentationGenerator_GenerateMarkdown(b *testing.B) {
384384
}
385385
}
386386

387-
func TestDocumentationGenerator_OverwriteReadme(t *testing.T) {
387+
func TestDocumentationGenerator_SkipExistingReadme(t *testing.T) {
388388
tempDir := t.TempDir()
389389
readmePath := filepath.Join(tempDir, "README.md")
390390

@@ -418,31 +418,4 @@ func TestDocumentationGenerator_OverwriteReadme(t *testing.T) {
418418
require.NoError(t, err, "Failed to read generated README.md")
419419

420420
assert.Equal(t, string(content), "hello")
421-
422-
// regenerate
423-
docGen = &DocumentationGenerator{
424-
generator: generator,
425-
overwrite: true,
426-
}
427-
428-
err = docGen.generate()
429-
assert.NoError(t, err, "generate() unexpected error")
430-
431-
content, err = os.ReadFile(readmePath)
432-
require.NoError(t, err, "Failed to read generated README.md")
433-
434-
contentStr := string(content)
435-
436-
assert.Contains(t, contentStr, "# testextension Extension", "README should contain extension title")
437-
assert.Contains(t, contentStr, "Auto-generated PHP extension from Go code.", "README should contain description")
438-
439-
if len(generator.Functions) > 0 {
440-
assert.Contains(t, contentStr, "## Functions", "README should contain functions section when functions exist")
441-
442-
for _, fn := range generator.Functions {
443-
assert.Contains(t, contentStr, "### "+fn.Name, "README should contain function %s", fn.Name)
444-
assert.Contains(t, contentStr, fn.Signature, "README should contain function signature for %s", fn.Name)
445-
}
446-
}
447-
448421
}

internal/extgen/generator.go

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,13 @@ import (
66
)
77

88
type Generator struct {
9-
BaseName string
10-
SourceFile string
11-
BuildDir string
12-
Functions []phpFunction
13-
Classes []phpClass
14-
Constants []phpConstant
15-
Namespace string
16-
OverwriteReadme bool
9+
BaseName string
10+
SourceFile string
11+
BuildDir string
12+
Functions []phpFunction
13+
Classes []phpClass
14+
Constants []phpConstant
15+
Namespace string
1716
}
1817

1918
// EXPERIMENTAL
@@ -132,7 +131,6 @@ func (g *Generator) generateGoFile() error {
132131
func (g *Generator) generateDocumentation() error {
133132
docGen := DocumentationGenerator{
134133
generator: g,
135-
overwrite: g.OverwriteReadme,
136134
}
137135
if err := docGen.generate(); err != nil {
138136
return &GeneratorError{"documentation generation", "failed to generate documentation", err}

0 commit comments

Comments
 (0)