Skip to content

Commit 664cd2c

Browse files
authored
Merge pull request #330 from Warchant/master
Add @file flag parsing syntax
2 parents e53bd90 + d6cd691 commit 664cd2c

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

main.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ package main
55
import (
66
"fmt"
77
"os"
8+
"strings"
89

910
"github.com/boyter/scc/v3/processor"
1011
"github.com/spf13/cobra"
@@ -16,6 +17,23 @@ func main() {
1617
//pprof.StartCPUProfile(f)
1718
//defer pprof.StopCPUProfile()
1819

20+
if len(os.Args) == 2 && strings.HasPrefix(os.Args[1], "@") {
21+
// handle "scc @flags.txt" syntax
22+
filepath := strings.TrimPrefix(os.Args[1], "@")
23+
b, err := os.ReadFile(filepath)
24+
if err != nil {
25+
fmt.Printf("Error reading flags from a file: %s\n", err)
26+
os.Exit(1)
27+
}
28+
29+
args := strings.Split(string(b), "\n")
30+
var newArgs []string
31+
for _, x := range args {
32+
newArgs = append(newArgs, strings.TrimSpace(x))
33+
}
34+
os.Args = append([]string{os.Args[0]}, newArgs...)
35+
}
36+
1937
rootCmd := &cobra.Command{
2038
Use: "scc [flags] [files or directories]",
2139
Short: "scc [files or directories]",

test-all.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
#!/bin/bash
22

3+
# make sure this script can be executed from any dir
4+
cd $(dirname $0)
5+
36
GREEN='\033[1;32m'
47
RED='\033[0;31m'
58
NC='\033[0m'
@@ -28,6 +31,24 @@ echo '```' > LANGUAGES.md
2831
./scc --languages >> LANGUAGES.md
2932
echo '```' >> LANGUAGES.md
3033

34+
35+
echo "Running with @file flag parsing syntax"
36+
# include \n, \r\n and no line terminators
37+
echo -e "go.mod\ngo.sum\r\nLICENSE" > flags.txt
38+
if ./scc @flags.txt ; then
39+
echo -e "${GREEN}PASSED @file flag syntax"
40+
# post processing
41+
rm flags.txt
42+
else
43+
echo -e "${RED}======================================================="
44+
echo -e "FAILED Should handle @file flag parsing syntax"
45+
echo -e "=======================================================${NC}"
46+
# post processing
47+
rm flags.txt
48+
exit
49+
fi
50+
51+
3152
echo "Building HTML report..."
3253

3354
./scc --format html -o SCC-OUTPUT-REPORT.html

0 commit comments

Comments
 (0)