Skip to content

Commit edde111

Browse files
committed
✨ Add --verbose flag to sniff command
- Added --verbose/-v flag for detailed detection information - Shows which files are analyzed and which packages are found - Displays how each service is detected (based on which packages) - Provides comprehensive analysis tree for debugging - Removed redundant main_test.go (fixtures_test.go covers functionality better) - Fixed unused import in fixtures_test.go - Cleaned up generated sitedog.yml artifacts from testdata - Updated .gitignore to exclude testdata/*/sitedog.yml Version: v0.6.5
1 parent 4de55f0 commit edde111

File tree

4 files changed

+133
-389
lines changed

4 files changed

+133
-389
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ sitedog.html
88
sitedog
99
.DS_Store
1010
test-project/sitedog.yml
11+
testdata/*/sitedog.yml

fixtures_test.go

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package main
33
import (
44
"fmt"
55
"io/ioutil"
6-
"os"
76
"path/filepath"
87
"sort"
98
"testing"
@@ -213,39 +212,13 @@ func TestSpecificServiceDetection(t *testing.T) {
213212
t.Fatalf("Failed to load services data: %v", err)
214213
}
215214

216-
// Debug: Check if we loaded services data
217-
t.Logf("DEBUG: Loaded %d services from embed files", len(servicesData))
218-
if len(servicesData) == 0 {
219-
t.Fatalf("ERROR: No services data loaded from embed files!")
220-
}
215+
221216

222217
for _, tt := range tests {
223218
t.Run(fmt.Sprintf("%s_%s", tt.project, tt.service), func(t *testing.T) {
224219
projectPath := filepath.Join("testdata", tt.project)
225220

226-
// Debug: Check if the service exists in loaded data
227-
if serviceData, exists := servicesData[tt.service]; exists {
228-
t.Logf("DEBUG: Service %s found in data with %d stacks", tt.service, len(serviceData.Stacks))
229-
} else {
230-
t.Logf("DEBUG: Service %s NOT found in loaded data!", tt.service)
231-
t.Logf("DEBUG: Available services: %v", func() []string {
232-
var keys []string
233-
for k := range servicesData {
234-
keys = append(keys, k)
235-
}
236-
return keys
237-
}())
238-
}
239221

240-
// Debug: Check if testdata file exists and has content
241-
if files, err := filepath.Glob(filepath.Join(projectPath, "*")); err == nil {
242-
t.Logf("DEBUG: Files in %s: %v", projectPath, files)
243-
for _, file := range files {
244-
if info, err := os.Stat(file); err == nil {
245-
t.Logf("DEBUG: %s size: %d bytes", filepath.Base(file), info.Size())
246-
}
247-
}
248-
}
249222

250223
detectedLanguages := detectProjectLanguages(projectPath, stackData)
251224
if len(detectedLanguages) == 0 && tt.shouldFind {
@@ -254,13 +227,7 @@ func TestSpecificServiceDetection(t *testing.T) {
254227

255228
results := analyzeProjectDependencies(projectPath, detectedLanguages, stackData, servicesData)
256229

257-
// Debug: Show what files were analyzed
258-
for _, result := range results {
259-
t.Logf("DEBUG: Analyzed %d files for language %s", len(result.Files), result.Language)
260-
for _, file := range result.Files {
261-
t.Logf("DEBUG: - %s", file)
262-
}
263-
}
230+
264231

265232
found := false
266233
for _, result := range results {
@@ -275,17 +242,7 @@ func TestSpecificServiceDetection(t *testing.T) {
275242
}
276243
}
277244

278-
if found != tt.shouldFind {
279-
// Debug info for CI
280-
t.Logf("DEBUG: Languages detected: %v", detectedLanguages)
281-
t.Logf("DEBUG: Total results: %d", len(results))
282-
for i, result := range results {
283-
t.Logf("DEBUG: Result %d - Language: %s, Services: %d", i, result.Language, len(result.Services))
284-
for j, service := range result.Services {
285-
t.Logf("DEBUG: Service %d: %s", j, service.Name)
286-
}
287-
}
288-
245+
if found != tt.shouldFind {
289246
if tt.shouldFind {
290247
t.Errorf("Expected to find service %s in %s, but it was not detected", tt.service, tt.project)
291248
} else {

main.go

Lines changed: 129 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ const (
4545
globalTemplatePath = ".sitedog/demo.html.tpl"
4646
authFilePath = ".sitedog/auth"
4747
apiBaseURL = "https://app.sitedog.io"
48-
Version = "v0.6.4"
48+
Version = "v0.6.5"
4949
)
5050

5151
func main() {
@@ -90,18 +90,21 @@ Commands:
9090
Options for serve:
9191
--port PORT Port to run server on (default: 8081)
9292
93+
Options for sniff:
94+
--verbose, -v Show detailed detection information
95+
9396
Options for render:
9497
--output PATH Path to output HTML file (default: sitedog.html)
9598
9699
Examples:
97100
sitedog sniff # detect stack and create sitedog.yml
98101
sitedog sniff ./my-project # detect stack in directory and create config
102+
sitedog sniff --verbose # show detailed detection process
103+
sitedog sniff -v ./my-project # verbose analysis of specific directory
99104
100105
sitedog serve --port 3030`)
101106
}
102107

103-
104-
105108
func startServer(configFile *string, port int) (*http.Server, string) {
106109
// Handlers
107110
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
@@ -672,10 +675,23 @@ type PackageInfo struct {
672675
}
673676

674677
func handleSniff() {
675-
// Parse arguments - path can be positional argument
678+
// Parse arguments - path can be positional argument and flags
676679
var projectPath, configPath string
677-
if len(os.Args) >= 3 {
678-
argPath := os.Args[2]
680+
var verbose bool
681+
682+
// Parse flags first
683+
args := os.Args[2:] // Skip 'sitedog' and 'sniff'
684+
for i, arg := range args {
685+
if arg == "--verbose" || arg == "-v" {
686+
verbose = true
687+
// Remove this flag from args
688+
args = append(args[:i], args[i+1:]...)
689+
break
690+
}
691+
}
692+
693+
if len(args) >= 1 {
694+
argPath := args[0]
679695
if strings.HasSuffix(argPath, ".yml") || strings.HasSuffix(argPath, ".yaml") {
680696
// Argument is a config file path - analyze parent directory, save to specified file
681697
configPath = argPath
@@ -800,7 +816,11 @@ func handleSniff() {
800816
}
801817

802818
// Display results
803-
displayDetectorResults(allResults)
819+
if verbose {
820+
displayDetailedResults(projectPath, detectedLanguages, stackData, servicesData, allResults)
821+
} else {
822+
displayDetectorResults(allResults)
823+
}
804824

805825
// Create or update configuration
806826
createConfigFromDetectorResults(configPath, allResults)
@@ -1584,3 +1604,105 @@ func (a *ServicesDependenciesAdapter) GetServicesData() map[string]*detectors.Se
15841604
}
15851605
return result
15861606
}
1607+
1608+
func displayDetailedResults(projectPath string, detectedLanguages []string, stackData *StackDependencyFiles, servicesData map[string]*ServiceData, allResults map[string]string) {
1609+
fmt.Printf("🔍 Detailed Detection Analysis\n")
1610+
fmt.Printf("═══════════════════════════════\n\n")
1611+
1612+
// Show detected languages
1613+
if len(detectedLanguages) > 0 {
1614+
fmt.Printf("📝 Languages detected: %s\n\n", strings.Join(detectedLanguages, ", "))
1615+
1616+
// Analyze project dependencies with detailed output
1617+
results := analyzeProjectDependencies(projectPath, detectedLanguages, stackData, servicesData)
1618+
1619+
for _, result := range results {
1620+
fmt.Printf("🔧 %s Analysis:\n", strings.Title(result.Language))
1621+
fmt.Printf("├── Files analyzed: %d\n", len(result.Files))
1622+
1623+
for _, file := range result.Files {
1624+
fmt.Printf("│ ├── %s\n", file)
1625+
1626+
// Show packages found in this file
1627+
fileServices := analyzeFile(file, result.Language, servicesData)
1628+
if len(fileServices) > 0 {
1629+
for _, service := range fileServices {
1630+
fmt.Printf("│ │ └── %s service detected\n", service.Name)
1631+
for _, pkg := range service.Packages {
1632+
fmt.Printf("│ │ ├── Package: %s\n", pkg.Name)
1633+
}
1634+
}
1635+
} else {
1636+
fmt.Printf("│ │ └── No service packages found\n")
1637+
}
1638+
}
1639+
1640+
fmt.Printf("│\n")
1641+
fmt.Printf("├── Services found: %d\n", len(result.Services))
1642+
for _, service := range result.Services {
1643+
if serviceData, exists := servicesData[service.Name]; exists {
1644+
fmt.Printf("│ ├── %s → %s\n", serviceData.Name, serviceData.URL)
1645+
fmt.Printf("│ │ └── Based on packages: %s\n", func() string {
1646+
var packages []string
1647+
for _, pkg := range service.Packages {
1648+
packages = append(packages, pkg.Name)
1649+
}
1650+
return strings.Join(packages, ", ")
1651+
}())
1652+
} else {
1653+
fmt.Printf("│ ├── %s (unknown service)\n", service.Name)
1654+
}
1655+
}
1656+
fmt.Printf("│\n")
1657+
}
1658+
1659+
fmt.Printf("└── Analysis complete\n\n")
1660+
} else {
1661+
fmt.Printf("❌ No languages detected in project\n\n")
1662+
}
1663+
1664+
// Show repository information
1665+
if repo, hasRepo := allResults["repo"]; hasRepo {
1666+
fmt.Printf("📁 Repository: %s\n\n", repo)
1667+
}
1668+
1669+
// Show final summary
1670+
serviceCount := len(allResults)
1671+
if _, hasRepo := allResults["repo"]; hasRepo {
1672+
serviceCount-- // Don't count repo as a service
1673+
}
1674+
1675+
if serviceCount > 0 {
1676+
fmt.Printf("✨ Summary: %d service(s) detected\n", serviceCount)
1677+
fmt.Printf("═══════════════════════════════════\n")
1678+
1679+
// Show services in sorted order
1680+
var keys []string
1681+
for key := range allResults {
1682+
if key != "repo" {
1683+
keys = append(keys, key)
1684+
}
1685+
}
1686+
sort.Strings(keys)
1687+
1688+
for _, key := range keys {
1689+
value := allResults[key]
1690+
displayName := key
1691+
1692+
// Try to get proper display name
1693+
if servicesData != nil {
1694+
if serviceData, exists := servicesData[key]; exists {
1695+
displayName = serviceData.Name
1696+
}
1697+
}
1698+
1699+
if displayName == key {
1700+
displayName = getTechnologyDisplayName(key, value)
1701+
}
1702+
1703+
fmt.Printf(" 🔗 %s → %s\n", displayName, value)
1704+
}
1705+
} else {
1706+
fmt.Printf("❌ No services detected\n")
1707+
}
1708+
}

0 commit comments

Comments
 (0)