Skip to content

Commit

Permalink
fix command line
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenkristian committed Aug 15, 2022
1 parent 6b52199 commit 7e1ed30
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 20 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
## Experimental Command
- auth
### Experimental Command
- ## auth
```bash
pinata auth :auth_key
```
create file for store key api before use other command, put your JWT Key to create file in current folder to save your key for request pinata API.
- list
- ## list
```bash
pinata list :file_name :query
```
save result of query to file (or create file if not exists).
- unpin-hash
- ## unpin-hash
```bash
pinata unpin-hash :hash
```
remove/unpin file by hash id from pinata.
- unpin-query
- ## unpin-query
```bash
pinata unpin-query :query
```
Expand Down
37 changes: 22 additions & 15 deletions cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"encoding/json"
"fmt"
"io/ioutil"
"os"

"rubenkristian.github.com/pinata-client/pinata"
Expand All @@ -24,39 +23,47 @@ func main() {
return
}

fileAut, err := ioutil.ReadFile(currentDir + "/pinata-auth.json")
if err != nil {
fmt.Println("No file pinata-auth.json in this directory, please set auth key by using \"client auth {jwt key}\"")
return
}

authPinata := &PinataAuth{}
err = json.Unmarshal(fileAut, authPinata)
if err != nil {
fmt.Println("Failed to parse json file, please check file or set auth key by using \"client auth {jwt key}\"")
return
}

pinataApi := pinata.CreatePinata(authPinata.Key, 0, false)
switch args[0] {
case "auth":
createAuthFile(&currentDir, args[1])
case "list":
pinataApi := initPinata(&currentDir)
if len(args) >= 2 {
listFile(pinataApi, &currentDir, args[1], args[2])
} else {
fmt.Println("must have name file for save result of query")
}
case "unpin-hash":
pinataApi := initPinata(&currentDir)
unpinByHash(pinataApi, args)
case "unpin-query":
pinataApi := initPinata(&currentDir)
unpinByQuery(pinataApi, args)
}
} else {
fmt.Println("no command")
}
}

func initPinata(currDir *string) *pinata.Pinata {
fileAut, err := os.ReadFile(*currDir + "/pinata-auth.json")
if err != nil {
fmt.Println("No file pinata-auth.json in this directory, please set auth key by using \"client auth {jwt key}\"")
return nil
}

authPinata := &PinataAuth{}
err = json.Unmarshal(fileAut, authPinata)
if err != nil {
fmt.Println("Failed to parse json file, please check file or set auth key by using \"client auth {jwt key}\"")
return nil
}

pinataApi := pinata.CreatePinata(authPinata.Key, 0, false)

return pinataApi
}

func unpinByHash(pinata *pinata.Pinata, params []string) {
if len(params) == 2 {
pinata.RemoveByHash(params[1])
Expand Down

0 comments on commit 7e1ed30

Please sign in to comment.