Skip to content

Commit e9dfd5d

Browse files
committed
feat: run 명령어 추가 - 추적된 전체 파일 검사
git ls-files로 추적된 모든 파일에 대해 diff 명령어와 동일한 정책 검사를 수행. 스테이지 상태에 관계없이 워킹 트리 전체 검사. 검사 항목: - 바이너리 파일 감지 (RunBinaryFiles) - 인코딩 검사 UTF-8 (RunEncoding) - 데이터 파일 lint YAML/JSON/XML (RunLint) - editorconfig 규칙 (RunEditorConfig) - 주석 언어 전체 파일 (RunCommentLanguage)
1 parent fd5325f commit e9dfd5d

2 files changed

Lines changed: 435 additions & 0 deletions

File tree

cmd/run.go

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package cmd
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
"github.com/spf13/cobra"
8+
"github.com/zcube/commit-checker/internal/checker"
9+
"github.com/zcube/commit-checker/internal/config"
10+
)
11+
12+
var runCmd = &cobra.Command{
13+
Use: "run",
14+
Short: "Check all tracked files for policy compliance",
15+
Long: `Reads all files tracked by git (git ls-files) and checks:
16+
- binary file detection
17+
- file encoding (UTF-8)
18+
- data file lint (YAML, JSON/JSON5, XML)
19+
- .editorconfig compliance
20+
- comment language compliance
21+
22+
Unlike 'diff', this command checks all files regardless of staged state.`,
23+
RunE: func(cmd *cobra.Command, args []string) error {
24+
cfg, err := config.Load(configFile)
25+
if err != nil {
26+
return fmt.Errorf("failed to load config: %w", err)
27+
}
28+
29+
var allErrs []string
30+
31+
// 바이너리 파일 감지
32+
binErrs, err := checker.RunBinaryFiles(cfg)
33+
if err != nil {
34+
return fmt.Errorf("failed to check binary files: %w", err)
35+
}
36+
allErrs = append(allErrs, binErrs...)
37+
38+
// 인코딩 검사 (UTF-8)
39+
encErrs, err := checker.RunEncoding(cfg)
40+
if err != nil {
41+
return fmt.Errorf("failed to check encoding: %w", err)
42+
}
43+
allErrs = append(allErrs, encErrs...)
44+
45+
// 데이터 파일 lint (YAML, JSON, XML)
46+
lintErrs, err := checker.RunLint(cfg)
47+
if err != nil {
48+
return fmt.Errorf("failed to check lint: %w", err)
49+
}
50+
allErrs = append(allErrs, lintErrs...)
51+
52+
// .editorconfig 검사
53+
ecErrs, err := checker.RunEditorConfig(cfg)
54+
if err != nil {
55+
return fmt.Errorf("failed to check editorconfig: %w", err)
56+
}
57+
allErrs = append(allErrs, ecErrs...)
58+
59+
// 주석 언어 검사 (전체 파일)
60+
langErrs, err := checker.RunCommentLanguage(cfg)
61+
if err != nil {
62+
return fmt.Errorf("failed to check comment language: %w", err)
63+
}
64+
allErrs = append(allErrs, langErrs...)
65+
66+
if len(allErrs) > 0 {
67+
for _, e := range allErrs {
68+
fmt.Fprintln(os.Stderr, e)
69+
}
70+
os.Exit(1)
71+
}
72+
73+
return nil
74+
},
75+
}
76+
77+
func init() {
78+
rootCmd.AddCommand(runCmd)
79+
}

0 commit comments

Comments
 (0)