Skip to content

Commit

Permalink
Added command line flags for emitting full path (default) and a flatt…
Browse files Browse the repository at this point in the history
…ened structure (#20)
  • Loading branch information
jonasbn committed Feb 7, 2023
1 parent baeed21 commit 010aab2
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 28 deletions.
49 changes: 25 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# stevedore

`stevedore` is a small command line tool taking it's name from the worker working on the dock with loading cargo unto ships.
`stevedore` is a small command line tool taking it's name from the worker, working on the dock with loading cargo unto ships.

REF: [Wikipedia][WIKIPEDIA]

Expand All @@ -15,23 +15,23 @@ stevedore .
The above example

1. Locates the `.dockerignore` file
1. Reads the current directory (specified as `.`) recursively
1. Compares the located `.dockerignore` file with the contents of the specified directory
1. Outputs a report
2. Reads the current directory (specified as `.`) recursively
3. Compares the located `.dockerignore` file with the contents of the specified directory
4. Outputs a report

```text
. included
.dockerignore included
.gitignore included
README.md included
TODO included
go.mod included
go.sum included
main.go ignored
stevedore included
.
.dockerignore
.gitignore
README.md
TODO
go.mod
go.sum
main.go
stevedore
```

You can actually emit the path parameter, `stevedore` defaults to current directory.
You can actually emit the path parameter, since `stevedore` defaults to current directory.

## Parameters

Expand All @@ -47,6 +47,7 @@ Since this is just an analysis/reporting tool it can be fed with parameters to d
- `--excluded` emits only excluded files (ignored)
- `--invertcolors` inverts the used colors
- `--stdin` / `-s` reads ignore file from STDIN
- `--fullpath` / `-f` emits full path of encountered files and directories

### Verbosity

Expand All @@ -57,15 +58,15 @@ stevedore -verbose .
```

```text
path . not ignored and is included in Docker image
path .dockerignore not ignored and is included in Docker image
path .gitignore not ignored and is included in Docker image
path README.md not ignored and is included in Docker image
path TODO not ignored and is included in Docker image
path go.mod not ignored and is included in Docker image
path go.sum not ignored and is included in Docker image
path main.go ignored and is included in Docker image
path stevedore not ignored and is included in Docker image
path . is not ignored and is included in Docker image
path .dockerignore is not ignored and is included in Docker image
path .gitignore is not ignored and is included in Docker image
path README.md is not ignored and is included in Docker image
path TODO is not ignored and is included in Docker image
path go.mod is not ignored and is included in Docker image
path go.sum is not ignored and is included in Docker image
path main.go is ignored and is included in Docker image
path stevedore is not ignored and is included in Docker image
```

### Passing in a ignore file using either stdin and ignore file parameters
Expand All @@ -90,7 +91,7 @@ These will render the same result.

You can add an ignore file, named `.stevedoreignore` to your directory. It will tell `stevedore` what files and directories to ignore prior to making it's analysis.

Meaning that patterns in this files matched, will be excluded.
Meaning that patterns in this files matched, will be _excluded_.

The `.stevedoreignore` file follows the general implementation pattern. and example could be:

Expand Down
28 changes: 24 additions & 4 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ func realMain() int {
var colorOutputInverted bool
flag.BoolVar(&colorOutputInverted, "invertcolors", false, "inverts the used color")

var fullPath bool
flag.BoolVar(&fullPath, "fullpath", true, "emits files and directories with full path")
flag.BoolVar(&fullPath, "f", true, "emits files and directories with full path")

var noFullPath bool
flag.BoolVar(&noFullPath, "nofullpath", false, "emits files and directories without full path")

nocolorEnv := os.Getenv("NO_COLOR")

flag.Parse()
Expand Down Expand Up @@ -126,6 +133,7 @@ func realMain() int {
fmt.Println("verbose: ", verbose)
fmt.Println("excluded: ", excluded)
fmt.Println("included: ", included)
fmt.Println("fullpath: ", fullPath)
fmt.Println("tail: ", flag.Args())
fmt.Println("ENV: ", nocolorEnv)
}
Expand Down Expand Up @@ -153,6 +161,10 @@ func realMain() int {
ignoredColor, includedColor = includedColor, ignoredColor
}

if noFullPath {
fullPath = false
}

var err error

ownIgnoreFile := ".stevedoreignore"
Expand Down Expand Up @@ -193,15 +205,23 @@ func realMain() int {
return nil
}

var entry string

if fullPath {
entry = path
} else {
entry = info.Name()
}

if ignoreObject.MatchesPath(path) {
if excluded {
if colorOutput {
color.Set(ignoredColor)
}
if verbose {
fmt.Printf("path %s ignored and is not included in Docker image\n", info.Name())
fmt.Printf("path %s ignored and is not included in Docker image\n", entry)
} else {
fmt.Printf("%s\n", info.Name())
fmt.Printf("%s\n", entry)
}
color.Unset()
}
Expand All @@ -211,9 +231,9 @@ func realMain() int {
color.Set(includedColor)
}
if verbose {
fmt.Printf("path %s not ignored and is included in Docker image\n", info.Name())
fmt.Printf("path %s not ignored and is included in Docker image\n", entry)
} else {
fmt.Printf("%s\n", info.Name())
fmt.Printf("%s\n", entry)
}
color.Unset()
}
Expand Down

0 comments on commit 010aab2

Please sign in to comment.