-
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.
Uses cobra for running commands
- Loading branch information
Showing
10 changed files
with
184 additions
and
45 deletions.
There are no files selected for viewing
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,27 @@ | ||
name: goreleaser | ||
on: | ||
push: | ||
tags: | ||
- "*" | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
goreleaser: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v6 | ||
with: | ||
distribution: goreleaser | ||
version: "~> v2" | ||
args: release --clean | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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
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
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
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,43 +1,9 @@ | ||
package main | ||
|
||
import ( | ||
"flag" | ||
"github.com/rs/zerolog" | ||
"jmpeax.com/sec/monica/internal/logging" | ||
"jmpeax.com/sec/monica/pkg/runner" | ||
"os" | ||
) | ||
|
||
var ( | ||
verbosity = flag.Int("v", -1, "verbosity level") | ||
file = flag.String("f", "", "Mon File to run") | ||
headerOnly = flag.Bool("h", false, "Output headers only") | ||
"jmpeax.com/sec/monica/pkg/cmd" | ||
) | ||
|
||
func main() { | ||
flag.Parse() | ||
switch *verbosity { | ||
case 1: | ||
zerolog.SetGlobalLevel(zerolog.DebugLevel) | ||
case 2: | ||
zerolog.SetGlobalLevel(zerolog.TraceLevel) | ||
default: | ||
zerolog.SetGlobalLevel(zerolog.InfoLevel) | ||
} | ||
logging.Log.Info().Msg("Welcome to Monica!") | ||
if *file == "" { | ||
logging.Log.Error().Msg("No Mon File provided") | ||
return | ||
} | ||
monFile, err := os.Stat(*file) | ||
if err != nil { | ||
logging.Log.Error().Msgf("Mon File not found: %s", *file) | ||
return | ||
} | ||
if !monFile.Mode().IsRegular() { | ||
logging.Log.Error().Msgf("Mon File is not a regular file: %s", *file) | ||
return | ||
} | ||
logging.Log.Info().Msgf("Running Mon File: %s", *file) | ||
runner.RunSingleFile(*file, &runner.Opts{HeaderOnly: *headerOnly}) | ||
cmd.Execute() | ||
} |
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 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/rs/zerolog" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var ( | ||
debug bool | ||
rootCmd = &cobra.Command{ | ||
Use: "monica", | ||
Short: "Monica is a CLI tool to manage Network Requests", | ||
Long: `Monica is a CLI tool to manage Network Requests like http, grpc, etc.`, | ||
Version: "0.1.0", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
cmd.Help() | ||
}, | ||
PersistentPreRun: func(cmd *cobra.Command, args []string) { | ||
if debug { | ||
zerolog.SetGlobalLevel(zerolog.TraceLevel) | ||
} else { | ||
zerolog.SetGlobalLevel(zerolog.InfoLevel) | ||
} | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
rootCmd.AddCommand(run) | ||
rootCmd.PersistentFlags().BoolVarP(&debug, "debug", "d", false, "Enable Debug logging") | ||
} | ||
|
||
func Execute() error { | ||
return rootCmd.Execute() | ||
} |
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,86 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"jmpeax.com/sec/monica/internal/logging" | ||
"jmpeax.com/sec/monica/pkg/runner" | ||
) | ||
|
||
var ( | ||
singleFile string | ||
recursiveLevel int | ||
run = &cobra.Command{ | ||
Use: "run", | ||
Short: "Runs all mon files", | ||
Long: "Runs all mon files found in the current working directory", | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if singleFile != "" { | ||
runSingleFile(singleFile) | ||
} else { | ||
runAllFiles(recursiveLevel) | ||
} | ||
}, | ||
} | ||
) | ||
|
||
func init() { | ||
run.Flags().StringVarP(&singleFile, "single", "s", "", "runs a single mon file, path can be absolute o relative to current working directory") | ||
run.Flags().IntVarP(&recursiveLevel, "recursive", "r", 1, "runs all mon files in the current working directory and subdirectories up to the specified level") | ||
} | ||
|
||
func runSingleFile(file string) { | ||
runner.RunSingleFile(file, &runner.Opts{ | ||
HeaderOnly: false, | ||
}) | ||
} | ||
|
||
func runAllFiles(level int) { | ||
files, err := FindMonFiles(".", level) | ||
logging.Log.Info().Msgf("Found %d mon files", len(files)) | ||
if err != nil { | ||
logging.Log.Error().Err(err).Msg("Error finding mon files") | ||
os.Exit(1) | ||
} | ||
for _, file := range files { | ||
runner.RunSingleFile(file, &runner.Opts{ | ||
HeaderOnly: false, | ||
}) | ||
} | ||
} | ||
|
||
func FindMonFiles(root string, maxDepth int) ([]string, error) { | ||
var files []string | ||
|
||
err := filepath.WalkDir(root, func(path string, d os.DirEntry, err error) error { | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// Calculate the current depth | ||
relativePath, err := filepath.Rel(root, path) | ||
if err != nil { | ||
return err | ||
} | ||
depth := len(strings.Split(filepath.ToSlash(relativePath), "/")) | ||
|
||
// If the current depth exceeds maxDepth, skip this directory | ||
if d.IsDir() { | ||
if depth > maxDepth { | ||
return filepath.SkipDir | ||
} | ||
} else { | ||
// Check if the file ends with .mon | ||
if strings.HasSuffix(d.Name(), ".mon") { | ||
files = append(files, path) | ||
} | ||
} | ||
|
||
return nil | ||
}) | ||
|
||
return files, err | ||
} |
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
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
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