Skip to content

Commit

Permalink
args file
Browse files Browse the repository at this point in the history
  • Loading branch information
Yoshihiko Nishida committed Jul 1, 2016
1 parent d1507a9 commit ebfbe23
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 29 deletions.
37 changes: 18 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,35 +19,34 @@ $ brew install ngc224/txtmsk/txtmsk
#### Set password

- Mac OS X: Keychain
- Linux: Kernel keyring (login session)
- Linux: Filebase

```
$ txtmsk -p
```

#### Mask & Unmask

Text to mask
```
$ txtmsk 'I am a false phimosis'
lKce3vRDwOBa/H7BoEXcXcyw7ZC7LsVkXtmySIZd/sUxABa+caIvUsBB0YlMRJ0rcA
Text to mask to unmask (stdin)
```
$ echo 'I am a false phimosis' | txtmsk
K6GlWbcSmPpF8Hi7nKudRPo6rCFcA4M/4ze93ujU5bzgvUfYg9At40Y2xg7ReEXaOw
Text to unmask
```
$ txtmsk -u 'lKce3vRDwOBa/H7BoEXcXcyw7ZC7LsVkXtmySIZd/sUxABa+caIvUsBB0YlMRJ0rcA'
$ echo 'K6GlWbcSmPpF8Hi7nKudRPo6rCFcA4M/4ze93ujU5bzgvUfYg9At40Y2xg7ReEXaOw' | txtmsk -u
I am a false phimosis
```

Text to mask (stdin)
```
$ echo 'I am a false phimosis' | txtmsk
lKce3vRDwOBa/H7BoEXcXcyw7ZC7LsVkXtmySIZd/sUxABa+caIvUsBB0YlMRJ0rcA
Text to mask to unmask (file read)
```
$ cat my_secret.txt
I am a false phimosis
Text to unmask (stdin)
```
$ echo 'lKce3vRDwOBa/H7BoEXcXcyw7ZC7LsVkXtmySIZd/sUxABa+caIvUsBB0YlMRJ0rcA' | txtmsk -u
$ txtmsk my_secret.txt > my_secret.txtmsk.txt
$ cat my_secret.txtmsk.txt
K6GlWbcSmPpF8Hi7nKudRPo6rCFcA4M/4ze93ujU5bzgvUfYg9At40Y2xg7ReEXaOw
$ txtmsk -u my_secret.txtmsk.txt
I am a false phimosis
```

Expand All @@ -67,7 +66,7 @@ I am a <msk>false phimosis</msk>
I am a <msk>false phimosis</msk>
I am a <msk>false phimosis</msk>
$ cat secret.txt | txtmsk
$ txtmsk -u secret.txt
I am a <msk>n6kL28dZQURtJ3as/Hpsryp+OwBR2rAN3Dbgb3iT84Mz7/f3gIu7qhqF</msk>
I am a <msk>ruM8Rs1otjSrp5UhIOd5Z7Et6eC3zdBDlX3UaLvrPBAS0Hm6mOnZ1zjr</msk>
I am a <msk>9NbYFdyGKycism9hx5Pq1hwGLNxz9+89Y02IL5ux9Nwt0QaUQGZKMeVS</msk>
Expand All @@ -84,14 +83,14 @@ I am a <msk>9NbYFdyGKycism9hx5Pq1hwGLNxz9+89Y02IL5ux9Nwt0QaUQGZKMeVS</msk>
I am a <msk>ik02zV8PA2QxXV379KV0KRCVastEoJNVqkqEHyTKrb45Y05Rd142cQJn</msk>
I am a <msk>OK44PxypCUO7KvYH+U8iyaYRzvaoqcTh8yHMkvcenUNP+6seRvVgWLP8</msk>
$ cat secret.txtmsk.txt | txtmsk -u
$ txtmsk -u secret.txtmsk.txt
I am a <msk>false phimosis</msk>
I am a <msk>false phimosis</msk>
I am a <msk>false phimosis</msk>
I am a <msk>false phimosis</msk>
I am a <msk>false phimosis</msk>
$ cat secret.txtmsk.txt | txtmsk -u -t
$ txtmsk -u -t secret.txtmsk.txt
I am a false phimosis
I am a false phimosis
I am a false phimosis
Expand All @@ -102,7 +101,7 @@ I am a false phimosis
### Help

```
Usage: txtmsk [options] text
Usage: txtmsk [options] textfile
-h this help
-p set password
-t trim inline tags (unmask mode only)
Expand Down
2 changes: 1 addition & 1 deletion command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,6 @@ func New() *Command {
}

func (cmd *Command) ShowHelp() {
fmt.Fprintf(os.Stderr, "Usage: %s [options] text\n", os.Args[0])
fmt.Fprintf(os.Stderr, "Usage: %s [options] textfile\n", os.Args[0])
flag.PrintDefaults()
}
22 changes: 15 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package main
import (
"bufio"
"fmt"
"io"
"os"
"strings"

Expand Down Expand Up @@ -52,23 +53,30 @@ func run() error {
}

var text string
var reader io.Reader = os.Stdin

if len(cmd.Args) > 0 {
text = cmd.Args[0]
fp, err := os.Open(cmd.Args[0])

if err != nil {
return err
}

reader = fp
} else {
if terminal.IsTerminal(0) {
return nil
}
}

sc := bufio.NewScanner(os.Stdin)

for sc.Scan() {
text += sc.Text() + "\n"
}
sc := bufio.NewScanner(reader)

text = strings.TrimRight(text, "\n")
for sc.Scan() {
text += sc.Text() + "\n"
}

text = strings.TrimRight(text, "\n")

m, err := mask.New(pw)

if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion mask/mask.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ func newRealkey(key string) ([]byte, error) {

func (m *Mask) Mask(text string) (string, error) {
if !utf8.ValidString(text) {
return "", errors.New("Not a text")
return "", errors.New("This is not a text of utf8")
}

src := compress([]byte(text))
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package main

const version = "1.1.4"
const version = "1.1.6"

0 comments on commit ebfbe23

Please # to comment.