-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from jeffsvajlenko/mvp
Mvp
- Loading branch information
Showing
87 changed files
with
60,318 additions
and
13 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,4 +7,4 @@ vet: | |
go vet ./... | ||
|
||
build: | ||
go build -o bin/ ./cmd/goduped.go | ||
go build -o bin/goduped ./main.go |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
Copyright © 2021 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"GoDupeDetector/internal/detection" | ||
"GoDupeDetector/internal/parsing" | ||
"GoDupeDetector/internal/printer" | ||
"bufio" | ||
"errors" | ||
"fmt" | ||
"log" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// detectCmd represents the detect command | ||
var detectCmd = &cobra.Command{ | ||
Use: "detect", | ||
Short: "Runs clone detection.", | ||
Long: `Runs clone detection.`, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
|
||
input, _ := cmd.Flags().GetString("input") | ||
output, _ := cmd.Flags().GetString("output") | ||
|
||
finfo, err := os.Stat(input) | ||
if finfo == nil { | ||
return errors.New("Input directory does not exist or is invalid.") | ||
} | ||
if !finfo.IsDir() { | ||
return errors.New("Input must be a directory.") | ||
} | ||
|
||
finfo, err = os.Stat(output) | ||
if finfo != nil { | ||
return errors.New("Output file already exists or is a directory.") | ||
} | ||
outf, err := os.Create(output) | ||
if err != nil { | ||
return fmt.Errorf("Failed to create output file with error: %s", err.Error()) | ||
} | ||
defer outf.Close() | ||
|
||
fmt.Print("Collecting go files...") | ||
files, err := parsing.FileList(input) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
fmt.Printf(" %d files collected.\n", len(files)) | ||
|
||
fmt.Print("Parsing...") | ||
pset, _ := parsing.Parse(files) | ||
fmt.Println(" Done!") | ||
|
||
fmt.Print("Detecting...") | ||
cset, _ := detection.DetectClones(pset, 0.70) | ||
fmt.Printf(" %d clones detected.\n", len(cset.Clones)) | ||
|
||
fmt.Println("Outputting...") | ||
bout := bufio.NewWriter(outf) | ||
err = printer.PrintCloneReport(pset, cset, bout) | ||
|
||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
return nil | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(detectCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// detectCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// detectCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
detectCmd.Flags().String("input", "", "Input source folder.") | ||
detectCmd.MarkFlagRequired("input") | ||
detectCmd.Flags().String("output", "", "Output report file.") | ||
detectCmd.MarkFlagRequired("output") | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* | ||
Copyright © 2021 Jeffrey Svajlenko | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "goduped", | ||
Short: "GoDupeDetector: A golang clone detector.", | ||
Long: "GoDupeDetector: A golang clone detector.", | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
//Run: func(cmd *cobra.Command, args []string) { | ||
//}, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() error { | ||
return rootCmd.Execute() | ||
} | ||
|
||
func init() { | ||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
|
||
// rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.GoDupeDetector.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
//rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} | ||
|
||
func er(msg interface{}) { | ||
fmt.Println("Error:", msg) | ||
os.Exit(1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
Copyright © 2022 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// versionCmd represents the version command | ||
var versionCmd = &cobra.Command{ | ||
Use: "version", | ||
Short: "Prints the version of GoDupeDetector", | ||
Long: `Prints the version of GoDupeDetector:`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println("v0.0.1") | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(versionCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// versionCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// versionCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,27 @@ | ||
module "GoDupeDetector" | ||
module GoDupeDetector | ||
|
||
go 1.17 | ||
|
||
require github.com/spf13/cobra v1.3.0 | ||
|
||
require ( | ||
github.com/fsnotify/fsnotify v1.5.1 // indirect | ||
github.com/hashicorp/hcl v1.0.0 // indirect | ||
github.com/magiconair/properties v1.8.5 // indirect | ||
github.com/mitchellh/mapstructure v1.4.3 // indirect | ||
github.com/pelletier/go-toml v1.9.4 // indirect | ||
github.com/spf13/afero v1.6.0 // indirect | ||
github.com/spf13/cast v1.4.1 // indirect | ||
github.com/spf13/jwalterweatherman v1.1.0 // indirect | ||
github.com/subosito/gotenv v1.2.0 // indirect | ||
golang.org/x/sys v0.0.0-20211210111614-af8b64212486 // indirect | ||
golang.org/x/text v0.3.7 // indirect | ||
gopkg.in/ini.v1 v1.66.2 // indirect | ||
gopkg.in/yaml.v2 v2.4.0 // indirect | ||
) | ||
|
||
require ( | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/spf13/pflag v1.0.5 // indirect | ||
github.com/spf13/viper v1.10.1 // indirect | ||
) |
Oops, something went wrong.