Skip to content

Commit 56c53d4

Browse files
committed
init
1 parent 4fe4903 commit 56c53d4

File tree

3 files changed

+88
-0
lines changed

3 files changed

+88
-0
lines changed

.github/dependabot.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
version: 2
2+
updates:
3+
- package-ecosystem: "github-actions"
4+
directory: "/"
5+
schedule:
6+
interval: "daily"
7+
8+
- package-ecosystem: "gomod"
9+
directory: "/"
10+
schedule:
11+
interval: "daily"

go.mod

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module github.com/pkgforge-security/comb
2+
3+
go 1.23.1

main.go

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
package main
2+
3+
import (
4+
"bufio"
5+
"flag"
6+
"fmt"
7+
"os"
8+
)
9+
10+
func main() {
11+
var flip bool
12+
flag.BoolVar(&flip, "f", false, "")
13+
flag.BoolVar(&flip, "flip", false, "")
14+
15+
var separator string
16+
flag.StringVar(&separator, "s", "", "")
17+
flag.StringVar(&separator, "separator", "", "")
18+
19+
flag.Parse()
20+
21+
if flag.NArg() < 2 {
22+
flag.Usage()
23+
os.Exit(1)
24+
}
25+
26+
prefixFile, err := os.Open(flag.Arg(0))
27+
if err != nil {
28+
fmt.Fprintf(os.Stderr, "%s\n", err)
29+
os.Exit(1)
30+
}
31+
32+
suffixFile, err := os.Open(flag.Arg(1))
33+
if err != nil {
34+
fmt.Fprintf(os.Stderr, "%s\n", err)
35+
os.Exit(1)
36+
}
37+
38+
// use 'a' and 'b' because which is the prefix
39+
// and which is the suffix depends on if we're in
40+
// flip mode or not.
41+
fileA := prefixFile
42+
fileB := suffixFile
43+
44+
if flip {
45+
fileA, fileB = fileB, fileA
46+
}
47+
48+
a := bufio.NewScanner(fileA)
49+
for a.Scan() {
50+
// rewind file B so we can scan it again
51+
fileB.Seek(0, 0)
52+
53+
b := bufio.NewScanner(fileB)
54+
for b.Scan() {
55+
if flip {
56+
fmt.Printf("%s%s%s\n", b.Text(), separator, a.Text())
57+
} else {
58+
fmt.Printf("%s%s%s\n", a.Text(), separator, b.Text())
59+
}
60+
}
61+
}
62+
63+
}
64+
65+
func init() {
66+
flag.Usage = func() {
67+
fmt.Fprintf(os.Stderr, "Combine the lines from two files in every combination\n\n")
68+
fmt.Fprintf(os.Stderr, "Usage:\n")
69+
fmt.Fprintf(os.Stderr, " comb [OPTIONS] <prefixfile> <suffixfile>\n\n")
70+
fmt.Fprintf(os.Stderr, "Options:\n")
71+
fmt.Fprintf(os.Stderr, " -f, --flip Flip mode (order by suffix)\n")
72+
fmt.Fprintf(os.Stderr, " -s, --separator <str> String to place between prefix and suffix\n")
73+
}
74+
}

0 commit comments

Comments
 (0)