Skip to content
Merged
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
9 changes: 2 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,17 @@ For the details of the usage in the documentation and the code, please refer to

## Running

Embed Code operates in three modes:
Embed Code operates in two modes:

1. **Embedding**: Scans documentation files for `<embed-code>` tags and performs the requested embeddings,
overwriting the content of the target documentation files.

2. **Up-to-Date Check**: Compares the content under `<embed-code>` tags with the corresponding source code fragments.
If they differ, the tool reports which files are out-of-date.

3. **Analysis**: Verifies that all embeddings have matching source code fragments.
Any issues are logged to `build/analytics/problem-files.txt`.


The mode is selected using the mandatory `-mode` argument:
- `embed`: Performs the embedding process.
- `check`: Checks if embeddings are up-to-date.
- `analyze`: Runs the analysis process.

The tool can be run as a pre-compiled binary or via the Go compiler (requires Go [installed](#installation)).
Binaries are located in the `./bin` directory.
Expand All @@ -60,7 +55,7 @@ go run ./main.go [arguments]
### Arguments

The available arguments are:
* `-mode`: (Mandatory) The execution mode: `embed`, `check`, or `analyze`.
* `-mode`: (Mandatory) The execution mode: `embed` or `check`.
* `-code-path`: (Optional) Path to the source code root directory.
* `-docs-path`: (Optional) Path to the documentation root directory.
* `-config-path`: (Optional) Path to a YAML configuration file containing `code-path` and `docs-path`.
Expand Down
88 changes: 0 additions & 88 deletions analyzing/analyzing.go

This file was deleted.

13 changes: 2 additions & 11 deletions cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"os"
"strings"

"embed-code/embed-code-go/analyzing"
"embed-code/embed-code-go/configuration"
"embed-code/embed-code-go/embedding"

Expand Down Expand Up @@ -90,9 +89,8 @@ type EmbedCodeSamplesResult struct {
}

const (
ModeCheck = "check"
ModeEmbed = "embed"
ModeAnalyze = "analyze"
ModeCheck = "check"
ModeEmbed = "embed"
)

// CheckCodeSamples returns documentation files that are not up-to-date with code files.
Expand All @@ -112,13 +110,6 @@ func EmbedCodeSamples(config configuration.Configuration) EmbedCodeSamplesResult
}
}

// AnalyzeCodeSamples analyzes code fragments in documentation files.
//
// config — a configuration for embedding.
func AnalyzeCodeSamples(config configuration.Configuration) {
analyzing.AnalyzeAll(config)
}

// ReadArgs reads user-specified args from the command line.
//
// Returns Config struct filled with the corresponding args.
Expand Down
1 change: 0 additions & 1 deletion cli/cli_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ var _ = Describe("CLI validation", func() {
},

Entry("with check mode", cli.ModeCheck),
Entry("with analyze mode", cli.ModeAnalyze),
Entry("with embed mode", cli.ModeEmbed),
)

Expand Down
8 changes: 4 additions & 4 deletions cli/cli_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,19 +82,19 @@ func ValidateConfigFile(userConfig Config) error {
return errors.New("expected to use config file, but it does not exist")
}

// validateMode checks if mode is set to check, embed, or analyze.
// validateMode checks if mode is set to check or embed.
func validateMode(mode string) error {
isModeSet := isNotEmpty(mode)
if !isModeSet {
return errors.New("mode must be set")
}

validModes := []string{ModeEmbed, ModeAnalyze, ModeCheck}
validModes := []string{ModeEmbed, ModeCheck}
isValidMode := slices.Contains(validModes, mode)

if !isValidMode {
return fmt.Errorf("invalid value for mode. it must be one of — `%s`, `%s` or `%s`",
ModeEmbed, ModeCheck, ModeAnalyze)
return fmt.Errorf("invalid value for mode. it must be one of — `%s` or `%s`",
ModeEmbed, ModeCheck)
}

return nil
Expand Down
10 changes: 7 additions & 3 deletions embedding/commentfilter/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,9 @@ func filterFor(
warnUnsupportedFileType(filePath, mode, embeddingDocPath, embeddingLine)
return nil, false
}
warnUnsupportedCommentsMode(filePath, mode, embeddingDocPath, embeddingLine, entry.supportedModes)
if warnUnsupportedCommentsMode(filePath, mode, embeddingDocPath, embeddingLine, entry.supportedModes) {
return nil, false
}

return entry.filter, true
}
Expand Down Expand Up @@ -123,9 +125,9 @@ func warnUnsupportedCommentsMode(
embeddingDocPath string,
embeddingLine int,
supportedModes []Mode,
) {
) bool {
if containsMode(supportedModes, mode) {
return
return false
}
var wrappedModes []string
for _, mode := range supportedModes {
Expand All @@ -142,6 +144,8 @@ func warnUnsupportedCommentsMode(
strings.Join(wrappedModes, ", "),
),
)

return true
}

// fileURL returns an absolute file URL for a local path and line.
Expand Down
10 changes: 10 additions & 0 deletions embedding/commentfilter/filter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,6 +451,16 @@ var _ = Describe("Comment filter", func() {
Expect(output).Should(ContainSubstring("guide.md:12"))
Expect(output).Should(ContainSubstring("does not have a distinct meaning"))
})

It("should leave content unchanged when mode is not supported for file type", func() {
lines := []string{
"<root>",
" <!-- hidden -->",
"</root>",
}

assertFiltered("layout.xml", RetainDocumentation, lines, lines)
})
})
})

Expand Down
2 changes: 1 addition & 1 deletion embedding/commentfilter/visual_basic.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const (
)

// VisualBasicCommentFilter filters the Visual Basic comment forms:
// - documentation comments starting with `'`;
// - documentation comments starting with `'''`;
// - apostrophe comments starting with `'`;
// - REM comments starting with `REM`.
type VisualBasicCommentFilter struct{}
Expand Down
14 changes: 4 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const Version = "1.2.0"

// The entry point for embed-code.
//
// There are three modes, which are chosen by 'mode' arg. If it is set to 'check',
// then the checking for up-to-date is performed. If it is set to 'embed', the embedding is
// performed. If it is set to 'analyze', the analyzing is performed.
// There are two modes, which are chosen by 'mode' arg. If it is set to 'check',
// then the checking for up-to-date is performed. If it is set to 'embed',
// the embedding is performed.
//
// EmbeddingInstruction is the process that consists of the following steps:
// - the code fragments are extracted from the code files;
Expand Down Expand Up @@ -65,10 +65,9 @@ const Version = "1.2.0"
// - code-path — a path to a root directory with code files;
// - docs-path — a path to a root directory with docs files;
// - config-path — a path to a yaml configuration file;
// - mode — string which represents the mode of embed-code execution. if it is set to 'check',
// - mode — string which represents the mode of embed-code execution. If it is set to 'check',
// then the checking for up-to-date is performed. If it is set to 'embed', the embedding
// is performed.
// If it is set to 'analyze', the analyzing is performed;
// - doc-includes — a comma-separated string of glob patterns for docs files to include.
// For example:
// "docs/**/*.md,guides/*.html". Default value is "**/*.md,**/*.html";
Expand Down Expand Up @@ -112,11 +111,6 @@ func main() {
case cli.ModeEmbed:
embedByConfigs(configs)
fmt.Println("Embedding process finished.")
case cli.ModeAnalyze:
for _, config := range configs {
cli.AnalyzeCodeSamples(config)
}
fmt.Println("Analysis is completed, analytics files can be found in /build/analytics folder.")
}
}

Expand Down
Loading