Skip to content

Commit

Permalink
Add @file flag parsing syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Warchant committed Apr 5, 2022
1 parent e53bd90 commit d6cd691
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
18 changes: 18 additions & 0 deletions main.go
Expand Up @@ -5,6 +5,7 @@ package main
import (
"fmt"
"os"
"strings"

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

if len(os.Args) == 2 && strings.HasPrefix(os.Args[1], "@") {
// handle "scc @flags.txt" syntax
filepath := strings.TrimPrefix(os.Args[1], "@")
b, err := os.ReadFile(filepath)
if err != nil {
fmt.Printf("Error reading flags from a file: %s\n", err)
os.Exit(1)
}

args := strings.Split(string(b), "\n")
var newArgs []string
for _, x := range args {
newArgs = append(newArgs, strings.TrimSpace(x))
}
os.Args = append([]string{os.Args[0]}, newArgs...)
}

rootCmd := &cobra.Command{
Use: "scc [flags] [files or directories]",
Short: "scc [files or directories]",
Expand Down
21 changes: 21 additions & 0 deletions test-all.sh
@@ -1,5 +1,8 @@
#!/bin/bash

# make sure this script can be executed from any dir
cd $(dirname $0)

GREEN='\033[1;32m'
RED='\033[0;31m'
NC='\033[0m'
Expand Down Expand Up @@ -28,6 +31,24 @@ echo '```' > LANGUAGES.md
./scc --languages >> LANGUAGES.md
echo '```' >> LANGUAGES.md


echo "Running with @file flag parsing syntax"
# include \n, \r\n and no line terminators
echo -e "go.mod\ngo.sum\r\nLICENSE" > flags.txt
if ./scc @flags.txt ; then
echo -e "${GREEN}PASSED @file flag syntax"
# post processing
rm flags.txt
else
echo -e "${RED}======================================================="
echo -e "FAILED Should handle @file flag parsing syntax"
echo -e "=======================================================${NC}"
# post processing
rm flags.txt
exit
fi


echo "Building HTML report..."

./scc --format html -o SCC-OUTPUT-REPORT.html
Expand Down

0 comments on commit d6cd691

Please sign in to comment.