Skip to content

Commit b746d04

Browse files
authored
Merge pull request #50 from orangekame3/add-noreport
[feat]: add --noreport option
2 parents d46b6b8 + 402e903 commit b746d04

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

cmd/root.go

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,23 @@ import (
3939
)
4040

4141
var (
42-
awsProfile string
43-
awsRegion string
44-
endpointURL string
45-
local bool
46-
noColor bool
47-
mfa bool
48-
level int
49-
fullPath bool
50-
fileName string
51-
size bool
52-
humanReadable bool
53-
dateTime bool
54-
username bool
55-
directoryOnly bool
56-
pattern string
42+
awsProfile string
43+
awsRegion string
44+
endpointURL string
45+
local bool
46+
noColor bool
47+
mfa bool
48+
level int
49+
fullPath bool
50+
fileName string
51+
size bool
52+
humanReadable bool
53+
dateTime bool
54+
username bool
55+
directoryOnly bool
56+
pattern string
5757
inversePattern string
58+
noReport bool
5859
)
5960

6061
var rootCmd = &cobra.Command{
@@ -85,7 +86,7 @@ var rootCmd = &cobra.Command{
8586
if level > 0 {
8687
maxDepth = &level
8788
}
88-
keys, err := pkg.FetchS3ObjectKeys(s3Svc, bucket, prefix, maxDepth, size, humanReadable, dateTime, username,pattern,inversePattern)
89+
keys, err := pkg.FetchS3ObjectKeys(s3Svc, bucket, prefix, maxDepth, size, humanReadable, dateTime, username, pattern, inversePattern)
8990
if err != nil {
9091
log.Fatalf("failed to fetch S3 object keys: %v", err)
9192
return
@@ -112,14 +113,17 @@ var rootCmd = &cobra.Command{
112113
log.Fatalf("failed to output tree: %v", err)
113114
return
114115
}
115-
fmt.Fprintf(f, "\n%d directories, %d files\n", dirCount, fileCount)
116-
116+
if !noReport {
117+
fmt.Fprintf(f, "\n%d directories, %d files\n", dirCount, fileCount)
118+
}
117119
} else {
118120
if err := gtree.OutputProgrammably(os.Stdout, root); err != nil {
119121
log.Fatalf("failed to output tree: %v", err)
120122
return
121123
}
122-
fmt.Printf("\n%d directories, %d files\n", dirCount, fileCount)
124+
if !noReport {
125+
fmt.Printf("\n%d directories, %d files\n", dirCount, fileCount)
126+
}
123127
}
124128
},
125129
}
@@ -149,6 +153,7 @@ func init() {
149153
rootCmd.Flags().BoolVarP(&directoryOnly, "directory-only", "d", false, "List directories only.")
150154
rootCmd.Flags().StringVarP(&pattern, "pattern", "P", "", "List files that match the pattern.")
151155
rootCmd.Flags().StringVarP(&inversePattern, "inverse-pattern", "I", "", "List files that do not match the pattern.")
156+
rootCmd.Flags().BoolVarP(&noReport, "noreport", "", false, "Omits printing of the file and directory report at the end of the tree listing.")
152157

153158
}
154159

pkg/s3.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func formatBytes(b int64) string {
8888
}
8989

9090
// FetchS3ObjectKeys returns a slice of keys for all objects in the specified bucket and prefix
91-
func FetchS3ObjectKeys(s3Client *s3.Client, bucket string, prefix string, maxDepth *int, size, humanReadable bool, dateTime bool, username bool,pattern string,inversePattern string) ([][]string, error) {
91+
func FetchS3ObjectKeys(s3Client *s3.Client, bucket string, prefix string, maxDepth *int, size, humanReadable bool, dateTime bool, username bool, pattern string, inversePattern string) ([][]string, error) {
9292
var delimiter *string
9393
var fetchOwner *bool
9494
if maxDepth != nil {
@@ -167,7 +167,7 @@ func FetchS3ObjectKeys(s3Client *s3.Client, bucket string, prefix string, maxDep
167167
if include {
168168
keys = append(keys, key)
169169
}
170-
170+
171171
}
172172

173173
if maxDepth != nil {

0 commit comments

Comments
 (0)