Skip to content

Commit

Permalink
Add dev lines to README
Browse files Browse the repository at this point in the history
  • Loading branch information
jotadrilo committed Jun 17, 2019
1 parent dc666aa commit 6d4e329
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ bazel-out
bazel-testlogs
.vscode
dist
vendor
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
## Release 0.0.9 (2019-06-15)

- Sort folders on addition and deletion
- Re-create folder structure on restart

## Release 0.0.9 (2019-06-15)
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,3 +119,13 @@ This helper will prompt the list of folders and will ask for a folder number to
Folder to use: 1
> jotadrilo @ /tmp/rubbish/20190614 $
```
## Development
This projects uses `go mod` and `bazel`.
```
go mod vendor
bazel run //:gazelle
bazel build //:rubbi-sh-osx
```
14 changes: 11 additions & 3 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"sort"

"github.com/juju/errors"
"github.com/mmikulicic/multierror"
Expand Down Expand Up @@ -163,8 +164,8 @@ func (config *Config) AddFolder(name string) error {
return err
}

folders := append(config.Folders, folder)
config.Folders = folders
config.Folders = append(config.Folders, folder)
sortFolders(config.Folders)

if err := config.updateLatest(folder); err != nil {
return err
Expand Down Expand Up @@ -198,6 +199,7 @@ func (config *Config) RemoveFolder(fn int) error {
return errors.Errorf("failed to remove the folder: %+v", err)
}
config.Folders = remove(config.Folders, fn)
sortFolders(config.Folders)

// If we are removing the latest folder, point to the last folder in the list
if config.Latest.Path == targetFolder.Path {
Expand All @@ -209,7 +211,7 @@ func (config *Config) RemoveFolder(fn int) error {
// Iterate over the folder entries and create them again.
func (config *Config) Recreate() (errs error) {
for _, fol := range config.Folders {
if _, err := os.Stat(configFile); err != nil {
if _, err := os.Stat(fol.Path); err != nil {
if os.IsNotExist(err) {
if err := createFolder(fol); err != nil {
errs = multierror.Append(errs, errors.Errorf("failed to create folder %s: %+v", fol.Name, err))
Expand Down Expand Up @@ -246,3 +248,9 @@ func (config *Config) updateLatest(folder Folder) error {

return nil
}

func sortFolders(folders []Folder) {
sort.SliceStable(folders, func(i int, j int) bool {
return folders[i].Name < folders[j].Name
})
}
4 changes: 3 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"os"
"strconv"
"time"

"github.com/juju/errors"
)

var (
Expand Down Expand Up @@ -111,7 +113,7 @@ func run() error {
// Try to change to the target directory
if err := os.Chdir(config.Latest.Path); err != nil {
// There possibily was a restart that removed the `tmp` folder.
if err := config.AddFolder(config.Latest.Name); err != nil {
if err := config.Recreate(); err != nil {
return err
}
if err := os.Chdir(config.Latest.Path); err != nil {
Expand Down

0 comments on commit 6d4e329

Please sign in to comment.