mirror of
https://github.com/ludo-technologies/pyscn.git
synced 2025-10-06 00:59:45 +03:00
analyze: default HTML unified report (hybrid)
Default to HTML unified report for analyze when no flags; print stderr summary; auto-open only in interactive sessions; docs updated.
This commit is contained in:
16
README.md
16
README.md
@@ -48,10 +48,18 @@ Run `pyscn --help` or `pyscn <command> --help` for all options. Root `--verbose`
|
||||
### analyze
|
||||
Run all major analyses concurrently and generate a unified report.
|
||||
|
||||
Default behavior (no format flags):
|
||||
- Generates a unified HTML report under `.pyscn/reports/`
|
||||
- Prints a concise analysis summary to stderr
|
||||
- Auto-opens the HTML only in interactive (non‑CI) sessions; use `--no-open` to suppress
|
||||
|
||||
```bash
|
||||
# Unified HTML report for a directory
|
||||
# Unified HTML report (explicit)
|
||||
pyscn analyze --html src/
|
||||
|
||||
# Default (no flags) also generates HTML under `.pyscn/reports/`
|
||||
pyscn analyze src/
|
||||
|
||||
# JSON/YAML/CSV are also supported (auto-generates timestamped files)
|
||||
pyscn analyze --json src/ # Creates: .pyscn/reports/analyze_YYYYMMDD_HHMMSS.json (unless [output].directory overrides)
|
||||
|
||||
@@ -183,10 +191,10 @@ Notes:
|
||||
|
||||
- Default include patterns: `*.py` (`.pyi` stub files supported but not included by default); default exclude: `test_*.py`, `*_test.py`
|
||||
- **Output formats**:
|
||||
- `text` (default): Prints to stdout
|
||||
- `json`, `yaml`, `csv`, `html`: Auto-generate timestamped files
|
||||
- `text` (default): Prints to stdout (for individual commands)
|
||||
- `analyze` default (no flags): Generates HTML + prints stderr summary (hybrid); auto-open only in interactive (non‑CI) sessions; use `--no-open` to suppress
|
||||
- `json`, `yaml`, `csv`, `html`: Auto-generate timestamped files when selected
|
||||
- Default location: `.pyscn/reports/` under the current working directory (created if missing); override with `[output].directory`
|
||||
- HTML reports can be auto-opened with `--no-open` flag to disable
|
||||
- All commands generate timestamped output files for structured formats
|
||||
|
||||
## Installation
|
||||
|
||||
@@ -198,18 +198,19 @@ func (c *AnalyzeCommand) determineOutputFormat() (string, string, error) {
|
||||
return "", "", fmt.Errorf("only one output format flag can be specified")
|
||||
}
|
||||
|
||||
// Default to text if no format specified
|
||||
if formatCount == 0 {
|
||||
return "text", "", nil
|
||||
}
|
||||
// Default to HTML if no format specified (hybrid default: file + stderr summary)
|
||||
if formatCount == 0 {
|
||||
return "html", "html", nil
|
||||
}
|
||||
|
||||
return format, extension, nil
|
||||
}
|
||||
|
||||
// shouldGenerateUnifiedReport returns true if a unified report should be generated
|
||||
func (c *AnalyzeCommand) shouldGenerateUnifiedReport() bool {
|
||||
// Generate unified report if any format flag is set
|
||||
return c.html || c.json || c.csv || c.yaml
|
||||
// Always generate unified report in analyze mode.
|
||||
// Format is determined by flags or defaults to HTML.
|
||||
return true
|
||||
}
|
||||
|
||||
// outputComplexityReport outputs an individual complexity report (for backward compatibility)
|
||||
@@ -753,6 +754,19 @@ func containsAny(str string, substrings []string) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// isInteractiveEnvironment returns true if the environment appears to be
|
||||
// an interactive TTY session (and not CI), used to decide auto-open behavior.
|
||||
func isInteractiveEnvironment() bool {
|
||||
if os.Getenv("CI") != "" {
|
||||
return false
|
||||
}
|
||||
// Best-effort TTY detection without external deps
|
||||
if fi, err := os.Stderr.Stat(); err == nil {
|
||||
return (fi.Mode() & os.ModeCharDevice) != 0
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// runComplexityAnalysis runs complexity analysis with configured parameters
|
||||
func (c *AnalyzeCommand) runComplexityAnalysis(cmd *cobra.Command, args []string) error {
|
||||
response, err := c.runComplexityAnalysisWithResult(cmd, args)
|
||||
@@ -1065,16 +1079,20 @@ func (c *AnalyzeCommand) generateUnifiedReport(cmd *cobra.Command, result *Analy
|
||||
absPath = filename
|
||||
}
|
||||
|
||||
// Handle browser opening for HTML
|
||||
if format == "html" && !c.noOpen {
|
||||
fileURL := "file://" + absPath
|
||||
if err := service.OpenBrowser(fileURL); err != nil {
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "Warning: Could not open browser: %v\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "📊 Unified HTML report generated and opened: %s\n", absPath)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
// Handle browser opening for HTML
|
||||
if format == "html" {
|
||||
// Auto-open only when explicitly allowed and environment appears interactive
|
||||
if !c.noOpen && isInteractiveEnvironment() {
|
||||
fileURL := "file://" + absPath
|
||||
if err := service.OpenBrowser(fileURL); err != nil {
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "Warning: Could not open browser: %v\n", err)
|
||||
} else {
|
||||
fmt.Fprintf(cmd.ErrOrStderr(), "📊 Unified HTML report generated and opened: %s\n", absPath)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
// If not opened, fall through to standard success message
|
||||
}
|
||||
|
||||
// Display success message
|
||||
formatName := strings.ToUpper(format)
|
||||
|
||||
Reference in New Issue
Block a user