Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add @file flag parsing syntax #330

Merged
merged 1 commit into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
@@ -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