Skip to content

Commit 7fb9ddb

Browse files
authored
update (#34)
1 parent 47bbbd3 commit 7fb9ddb

File tree

5 files changed

+59
-10
lines changed

5 files changed

+59
-10
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Whether it's for verifying the file structure, sharing the structure with your t
4141
- **Depth level Specification**: With the new `--L` flag, you can now specify how many levels deep in the directory structure you'd like to visualize. This offers a more focused view, especially for large S3 buckets.
4242
- **Role Switching Support**: `stree` is now enhanced with the ability to switch AWS roles with MFA using the `--mfa` flag. This makes it easier to manage and view S3 buckets that require different IAM roles for access.
4343
- **Environment Variable Support**: `stree` now prioritizes environment variables for AWS Profile and Region settings. The tool will use the `AWS_PROFILE` environment variable if set, falling back to the `default` profile otherwise. Similarly, it will use the `AWS_REGION` or `AWS_DEFAULT_REGION` environment variables for the AWS region, if available. (see [AWS CLI Environment Variables](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html) for more information)
44+
- **Full Path Display**: With the `-f` flag, the full path of each file is now displayed in the output, making it easier to identify the location of each item within the S3 bucket.
4445

4546
# Install
4647

@@ -256,6 +257,7 @@ Flags:
256257
-n, --no-color Disable colorized output
257258
-p, --profile string AWS profile to use (default "default")
258259
-r, --region string AWS region to use (overrides the region specified in the profile)
260+
-f Print the full path prefix for each file.
259261
```
260262

261263
# License

cmd/root.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ var (
4646
noColor bool
4747
mfa bool
4848
level int
49+
fullPath bool
4950
)
5051

5152
var rootCmd = &cobra.Command{
@@ -80,10 +81,10 @@ var rootCmd = &cobra.Command{
8081

8182
root := gtree.NewRoot(bucket)
8283
if noColor {
83-
root = pkg.BuildTreeWithoutColor(root, keys)
84+
root = pkg.BuildTreeWithoutColor(root, bucket, keys, fullPath)
8485
} else {
8586
root = gtree.NewRoot(color.BlueString(bucket))
86-
root = pkg.BuildTreeWithColor(root, keys)
87+
root = pkg.BuildTreeWithColor(root, bucket, keys, fullPath)
8788
}
8889

8990
if err := gtree.OutputProgrammably(os.Stdout, root); err != nil {
@@ -111,6 +112,7 @@ func init() {
111112
rootCmd.Flags().BoolVarP(&noColor, "no-color", "n", false, "Disable colorized output")
112113
rootCmd.Flags().BoolVarP(&mfa, "mfa", "m", false, "Use Multi-Factor Authentication")
113114
rootCmd.Flags().IntVarP(&level, "level", "L", 0, "Descend only level directories")
115+
rootCmd.Flags().BoolVarP(&fullPath, "", "f", false, "Print the full path prefix for each file.")
114116
}
115117

116118
func extractBucketAndPrefix(input string) (string, string, error) {
@@ -128,11 +130,6 @@ func extractBucketAndPrefix(input string) (string, string, error) {
128130
return bucket, parts[1], nil
129131
}
130132

131-
// SetVersionInfo sets version and date to rootCmd
132-
func SetVersionInfo(version, date string) {
133-
rootCmd.Version = fmt.Sprintf("%s (Built on %s)", version, date)
134-
}
135-
136133
func defaultProfile() string {
137134
if p, ok := os.LookupEnv("AWS_PROFILE"); ok {
138135
return p

cmd/version.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Package cmd is a root command.
2+
/*
3+
Copyright © 2024 Takafumi Miyanaga <[email protected]>
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.
22+
*/
23+
package cmd
24+
25+
import "fmt"
26+
27+
// Version is a version of this application.
28+
const Version = "0.0.12"
29+
30+
// SetVersionInfo sets version and date to rootCmd
31+
func SetVersionInfo(version, date string) {
32+
rootCmd.Version = fmt.Sprintf("%s (Built on %s)", version, date)
33+
}

main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ import (
2828
)
2929

3030
func main() {
31-
cmd.SetVersionInfo(version, time.Now().String())
31+
cmd.SetVersionInfo(cmd.Version, time.Now().String())
3232
cmd.Execute()
3333
}

pkg/tree.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,37 @@
22
package pkg
33

44
import (
5+
"fmt"
6+
57
"github.com/ddddddO/gtree"
68
"github.com/fatih/color"
79
)
810

11+
// createFullPath creates a full path for each keys
12+
func createFullPath(bucket string, keys [][]string)[][]string {
13+
for i := range keys {
14+
keys[i][len(keys[i])-1] = fmt.Sprintf("%s/%s", bucket, keys[i][len(keys[i])-1])
15+
}
16+
return keys
17+
}
18+
919
// BuildTreeWithColor builds a tree with colored nodes
10-
func BuildTreeWithColor(root *gtree.Node, keys [][]string) *gtree.Node {
20+
func BuildTreeWithColor(root *gtree.Node, bucket string, keys [][]string, f bool) *gtree.Node {
21+
if f {
22+
keys = createFullPath(bucket, keys)
23+
}
24+
1125
for _, key := range keys {
1226
addNodeWithColor(root, key, 0)
1327
}
1428
return root
1529
}
1630

1731
// BuildTreeWithoutColor builds a tree without colored nodes
18-
func BuildTreeWithoutColor(root *gtree.Node, keys [][]string) *gtree.Node {
32+
func BuildTreeWithoutColor(root *gtree.Node, bucket string, keys [][]string, f bool) *gtree.Node {
33+
if f {
34+
keys = createFullPath(bucket, keys)
35+
}
1936
for _, key := range keys {
2037
addNodeWithoutColor(root, key, 0)
2138
}

0 commit comments

Comments
 (0)