Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new flags and dependencies for enhanced directory structure printing #15

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ To print the directory structure of the current folder:
pr
```

To print the directory structure of a specific folder:
To print the directory structure of a specific folder:****

```bash
pr -dir /path/to/your/folder
Expand Down Expand Up @@ -114,7 +114,7 @@ printLayout/

### `--sort-by`
- **Description**: Specifies the sorting criteria
- **Options**:
- **Options**:
- `name`: Sort by file/directory name
- `size`: Sort by file size
- `time`: Sort by modification time
Expand Down
29 changes: 28 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,38 @@ import (
func main() {
config := printer.Config{}

// Define flags here:
flag.StringVar(&config.DirPath, "dir", ".", "Directory path to print the structure of")
flag.StringVar(&config.OutputPath, "output", "", "Output file path")
flag.StringVar(&config.ExtFilter, "ext", "", "File extension filter (e.g., .go, .js)")
flag.BoolVar(&config.NoColor, "no-color", false, "Disable colorized output")
flag.StringVar(&config.OutputFormat, "format", "text", "Output format (text, json, xml, yaml)")
flag.StringVar(&config.DirColor, "dir-color", "blue", "Color for directories (e.g., blue, green, red)")
flag.StringVar(&config.FileColor, "file-color", "green", "Color for files (e.g., yellow, cyan, magenta)")
flag.StringVar(&config.ExecColor, "exec-color", "red", "Color for executables (e.g., red, green, blue)")
flag.StringVar(&config.SortBy, "sort-by", "name", "Sort by 'name', 'size', or 'time'")
flag.StringVar(&config.Order, "order", "asc", "Sort order 'asc' or 'desc'")

// Add --exclude flag to specify exclusion patterns
flag.Func("exclude", "Exclude files/directories matching the pattern (can be specified multiple times)", func(pattern string) error {
config.ExcludePatterns = append(config.ExcludePatterns, pattern)
return nil
})

// Parse flags
flag.Parse()

printer.PrintProjectStructure(config.DirPath, config.OutputPath, config.ExtFilter)
printer.PrintProjectStructure(
config.DirPath,
config.OutputPath,
config.ExtFilter,
!config.NoColor,
config.OutputFormat,
config.DirColor,
config.FileColor,
config.ExecColor,
config.ExcludePatterns,
config.SortBy,
config.Order,
)
}
11 changes: 11 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
module PrintLayout

go 1.23.5

require (
github.com/fatih/color v1.18.0
gopkg.in/yaml.v3 v3.0.1
)

require (
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
golang.org/x/sys v0.25.0 // indirect
)
15 changes: 15 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
github.com/fatih/color v1.18.0 h1:S8gINlzdQ840/4pfAwic/ZE0djQEH3wM94VfqLTZcOM=
github.com/fatih/color v1.18.0/go.mod h1:4FelSpRwEGDpQ12mAdzqdOukCy4u8WUtOY6lkT/6HfU=
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
golang.org/x/sys v0.25.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Loading
Loading