Skip to content

Commit

Permalink
Apply patch v0.2B (#26)
Browse files Browse the repository at this point in the history
* ✔️ Mispells fixes

* Improvement of the ``rm`` command (#21) (#25)

* ✔️ Mispells fixes

* 🚧 Work on rework of rm command starts -- bad

* 💊 Fixed missspelling

* ✔️🏁 processArgsRm added + tests

* ✔️🏁 New feature for rm
	-> Added & adapted tests only for the ones impacted by those changes

* 💻🏁 Added test for rm.go:simpleDelAllString()
	-> Few changes (variadic params instead of slice)
	-> Some update for the ``$HOME`` on Windows

* ✔️🏁 Added handler for ``*`` wildcard as argument
	-> Tests, were adapted for that

* 📝 Update of usage for ``rm`` and deletion of deprecated stuff

* Implementation of ``tempest list --fix`` flag (#27)

* 🚧 Added the functionality, now needs the tests

* 🏁 Tests for list.go (``--fix`` flag related)
	+ Begin of migration to the use of Target instead of simple strings

-----------------------
Merge Fixes #20

* 🔨 Auto mode for TEMPest (#28)

* 🚧 Moved configs files for TEMpest into a directory
	[+] Added .sh for auto-mode
	--> Issues related: #24, #15
* Handler for shutup mode made, need merge
* Stash pop
* 🏁 Added tests for shutup mode handler (start.go)
	-> Issues related: #15, #16
* ✔️🏁 Added logs flag for get command
	[+] Added the corresponding test
	--> Issues related: #15, #16
* ✔️ Added handler for relative paths with ``add``
* 🏁 Added tests for treatRelativePath()
* 🏁 Test for getAllLogs() (--logs)
	--> Issues related: #15, #16
	[*] Should be the end of the Linux part for this one
* 💻 Windows autostart kinda done for theoric part
	[#] Issues related: #15, #9
	[T] Unit tests for set.go:setAutoStart()
	[T] Runtime testing for Windows
* 📛 Hot fix for codecov chmod
* 🏁 Test only for error checks
	[I] #15, #16
	[T] More elaborated tests for setAutoStart()
	[#] Fixes #15

* ➕ New flag for get (auto-mode)
	[+] Also implemented test func for it
	[#] Issues: #15, #16

* 📝 Update of README.md

* ⬆️ dep ensure

* Manage temp files (#30)

* 🚧 Started to refractor purge to purge files
	[T] Keep refratoring each functions affected
	[#] Issues: #17
	[N] Some comments were deleted (cobra related)

* New func to display size + units

* 📄🚽 Implemented the file purging
	[T] Tests
	[#] #30, #17

* 🏁 Tests for purge
👉 Apply TreatLastChar() to conf.Gobin & conf.Gopath
  • Loading branch information
ChacaS0 authored May 1, 2018
1 parent bf1ab1d commit 19ca504
Show file tree
Hide file tree
Showing 63 changed files with 1,812 additions and 7,903 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ before_install:
- go get -u github.com/golang/dep

script:
- chmod +x coverage.sh
- go install -v ./... && ./coverage.sh
- chmod +x scripts/coverage.sh
- go install -v ./... && ./scripts/coverage.sh
- go test -v -race ./...

after_success:
Expand Down
29 changes: 4 additions & 25 deletions Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Gopkg.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@

[[constraint]]
name = "github.com/spf13/cobra"
version = "0.0.1"
version = "0.0.2"

[[constraint]]
name = "github.com/spf13/viper"
Expand Down
35 changes: 21 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- [Through text editor](#through-text-editor)
- [List the current directories added to **TEMPest**](#list-the-current-directories-added-to-tempest)
- [Using **TEMPest**](#using-tempest)
- [Viewing the file ``~/.tempestcf``](#viewing-the-file-tempestcf)
- [Viewing the file ``.tempestcf``](#viewing-the-file-tempestcf)
- [Runing a global purge](#runing-a-global-purge)
- [Test mode](#test-mode)
- [Real one](#real-one)
Expand All @@ -45,6 +45,9 @@ or
export GOBIN=/usr/bin
```

> You can also skip this step and then just add a symlink from ``$GOBIN/tempest`` to ``/usr/bin/tempest`` after the installation of **TEMPest**

Then
```bash
go get -v -u github.com/ChacaS0/tempest
Expand All @@ -56,6 +59,7 @@ GOBIN=<PATH_OF_YOUR_CHOICE>
PATH=$PATH:$GOBIN
```


Then
```bash
go get -v -u github.com/ChacaS0/tempest
Expand All @@ -70,15 +74,15 @@ First, to initialize it the first time, run:
> tempest init
```

This will generate a ``~/.tempestcf`` file.
This will generate a ``.tempestcf`` file in ``$HOME/.tempest``.
It will hold the list of all the temp directories.

> If there is an issue and the file can't be created somehow, you can still create it at its default location: ``$HOME/.tempestcf`` and leave it empty for now.
> If there is an issue and the file can't be created somehow, you can still create it at its default location: ``$HOME/.tempest/.tempestcf`` and leave it empty for now.
This will also generate a ``~/.tempest.yaml`` file.
This will also generate a ``$HOME/.tempest/.tempest.yaml`` file.
It will hold the configuration of **TEMPest**.

> If there is an issue and the file can't be created somehow, you can still crate it at its default location: ``$HOME/.tempest.yaml`` with default content:
> If there is an issue and the file can't be created somehow, you can still crate it at its default location: ``$HOME/.tempest/.tempest.yaml`` with default content:
```yaml
duration: 5
auto-mode: false
Expand All @@ -87,7 +91,7 @@ auto-mode: false
* **duration** : This is the maximum age the content of the temp directories, choose it carefully!
> *You have to choose a duration greater than 1, it is for your own safety!!*
> *You have to choose a duration greater than 1 !!*
## Add a new temp folder to the list
### To add the current directory
Expand All @@ -109,10 +113,10 @@ tempest add ...<PATH>
* **``<PATH>``** being the path to the directory to be added to the list of temp directories
* **``...``** meaning that many arguments can be passed

> **By convention we will give the name ``temp`` to the directories to be added to ``tempest``**
> **By convention we will give the name ``temp`` to the directories to be added to ``TEMPest``**
### Through text editor
Just open ``~/.tempestcf`` and add a new line with the <u>absolute path</u> of the temp directory to be added.
Just open ``$HOME/.tempest/.tempestcf`` and add a new line with the <u>absolute path</u> of the temp directory to be added.

## List the current directories added to TEMPest
### Using TEMPest
Expand All @@ -121,18 +125,18 @@ Just open ``~/.tempestcf`` and add a new line with the <u>absolute path</u> of t
$ tempest list
```

### Viewing the file ``~/.tempestcf``
``$ cat ~/.tempestcf``
### Viewing the file ``$HOME/.tempest/.tempestcf``
``$ cat $HOME/.tempest/.tempestcf``
Or
``$ vi ~/.tempestcf``
``$ vi $HOME/.tempest/.tempestcf``

## Updating TEMPest
```bash
$ tempest update
```

## Runing a global purge
*The age of the files deleted will be the one older than the number of days set as "duration" in ~/.tempest.yaml*
*The age of the files deleted will be the one older than the number of days set as "duration" in ``$HOME/.tempest/.tempest.yaml``*
### Test mode
In this mode, it will display the file it <u>would</u> delete plus the size.
**Nothing gets deleted**. To do so, try:
Expand All @@ -142,7 +146,7 @@ $ tempest start -t
```

### Real one
**Runing this will actually delete files/directories, make sure everything inside ``~/.tempestcf`` is meant to be there with ``tempest list`` first.**
**Runing this will actually delete files/directories, make sure everything inside ``$HOME/.tempest/.tempestcf`` is meant to be there with ``TEMPest list`` first.**

```bash
$ tempest start
Expand All @@ -151,7 +155,7 @@ $ tempest start
## Purging one directory
>*Still based on the config file*
It is possible to purge a directory even if it is not added to tempest. There is also a test mode for this one.
It is possible to purge a directory even if it is not added to TEMPest. There is also a test mode for this one.
### Test mode

```bash
Expand Down Expand Up @@ -182,6 +186,9 @@ There is also a "man like" view of the documentation.
$ tempest doc -m
```

## More
If you want to know more about **TEMPest**, visit <a href="https://chacas0.github.io/tempest" target="_blank">this page</a>.


-------------------
*Thanks to*
Expand Down
54 changes: 42 additions & 12 deletions cmd/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"io/ioutil"
"log"
"os"
"regexp"
"strings"

"github.com/spf13/viper"
Expand Down Expand Up @@ -72,19 +73,13 @@ func init() {
}

RootCmd.AddCommand(addCmd)
// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// addCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// addCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
// addCmd.Flags().StringVarP(&this, "this", "t", "nothing", "Points to current directory")
}

// func addLine(argFlags []string, args []string) error {
// addLine add each string as target into TEMPest (~/.tempestcf)
func addLine(args []string) error {
// Check if the path already exists first in tempestcf
// ctnt, errRead := ioutil.ReadFile(conf.Home + "/.tempestcf")
Expand All @@ -107,13 +102,14 @@ func addLine(args []string) error {
}
defer tmpcf.Close()

// Fetch current directory
this, errDir := os.Getwd()
if errDir != nil {
log.Fatal(errDir)
}

// if no args
if len(args) == 0 {
// Fetch current directory
this, errDir := os.Getwd()
if errDir != nil {
log.Fatal(errDir)
}
// Check if already exists
sliceThis := make([]string, 1)
sliceThis[0] = this
Expand Down Expand Up @@ -143,6 +139,9 @@ func addLine(args []string) error {
fmt.Println(redB("::"), color.RedString("Can't add this target, check it does exist >>"), path)
return errors.New("")
}
// In case it is a relative path
treatRelativePath(&path, this)

// Add all the paths passed in the file
nbBytes, errWS := tmpcf.WriteString(path + "\n")
if errWS != nil {
Expand All @@ -156,6 +155,37 @@ func addLine(args []string) error {
return nil
}

// treatRelativePath treats a string in case it is a relative path.
// The func does check if it should act and does the action.
// if the first character is not a pathSeparator or the first two chars are ``./``
// It shall be replaced by the full path of the working directory followed by a path separator.
func treatRelativePath(path *string, workingDir string) {
// setup
var matchSimpleRel string
var matchDotRel string
workingDir += string(os.PathSeparator)

// regexes
// for match
regSimpleRel := regexp.MustCompile(`^([[:alpha:]]|[\d])`)
regDotRel := regexp.MustCompile(`^(\.(\/|\\))`)

// Matching
// Simple Relative path (with the form ``Documents/temp``)
matchSimpleRel = regSimpleRel.FindString(*path)
// Dot Relative path (with the form ``./Documents/temp``)
matchDotRel = regDotRel.FindString(*path)

switch {
case matchSimpleRel != "":
// replace
*path = regSimpleRel.ReplaceAllString(*path, workingDir+matchSimpleRel)
case matchDotRel != "":
// replace
*path = regDotRel.ReplaceAllString(*path, workingDir)
}
}

// checkRedondance returns true if a string is contained in both slices
// Eventually it is used to check if the path has already been set in ~/.tempestcf
// It also checks ``sliceArgs`` with ``sliceArgs`` to see if there were multiple same paths
Expand Down
38 changes: 38 additions & 0 deletions cmd/add_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,44 @@ func TestTreatLastChar(t *testing.T) {
}
}

// TestTreatRelativePath is the test for treatRelativePath(path *string, workDir string) {}.
// Should check if it uses full path to the working dir when adding relative paths.
// It should do nothing for full paths.
func TestTreatRelativePath(t *testing.T) {
// working directory
workDir, errDir := os.Getwd()
if errDir != nil {
t.Log("[ERROR]:: Can't retrieve the current directory", errDir)
t.FailNow()
}
// params
p1 := "./Downloads/temp"
p2 := "Documents/temp"
p3 := conf.Gopath
// wants
w1 := workDir + "/Downloads/temp"
w2 := workDir + "/" + p2

var tests = []struct {
path string
wkdir string
want string
errT error
}{
{p1, workDir, w1, errors.New("[FAIL]:: Can't process './' types")},
{p2, workDir, w2, errors.New("[FAIL]:: Can't process 'Doc/temp... types")},
{p3, workDir, p3, errors.New("[FAIL]:: Should have done nothing, yet did much")},
}

for _, tst := range tests {
treatRelativePath(&tst.path, tst.wkdir)
if tst.path != tst.want {
t.Log(tst.errT, "\n\t[GOT]-> ", tst.path, "\n\t[WANT]->", tst.want)
t.Fail()
}
}
}

// TestAddLine is the test for addLine(args []string) error {}
// Check if it does add the proper line to a .tempestcf file.
func TestAddLine(t *testing.T) {
Expand Down
8 changes: 1 addition & 7 deletions cmd/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,9 @@ var docCmd = &cobra.Command{
func init() {
RootCmd.AddCommand(docCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// docCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// docCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")

docCmd.Flags().BoolVarP(&isMan, "man", "m", false, "Add this falg to have a \"man like\" view.")
}

Expand Down
Loading

0 comments on commit 19ca504

Please sign in to comment.