diff --git a/.gitignore b/.gitignore index 9f11b75..5f1a335 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .idea/ +lbryschema-cli diff --git a/build.sh b/build.sh index 43d669a..06fc6b0 100755 --- a/build.sh +++ b/build.sh @@ -4,4 +4,5 @@ set -euxo pipefail echo "Building protobuf files" rm -rf pb/*.pb.go protoc --go_out=. pb/*.proto -go build ./... \ No newline at end of file +go build ./... +go build ./cli/lbryschema-cli.go \ No newline at end of file diff --git a/cli/lbryschema-cli.go b/cli/lbryschema-cli.go new file mode 100644 index 0000000..e49bd9e --- /dev/null +++ b/cli/lbryschema-cli.go @@ -0,0 +1,43 @@ +package main + +import ( + "os" + "../claim" + "fmt" +) + +func main() { + args := os.Args[1:] + if len(args) == 1 { + claim_bytes := []byte(args[0]) + decoded, err := claim.DecodeClaimBytes(claim_bytes) + if err != nil { + fmt.Println("Decoding error:", err) + return + } + text, err := decoded.RenderJSON() + if err != nil { + fmt.Println("Decoding error:", err) + return + } + fmt.Println(text) + return + } else if (len(args) == 2) && (args[1] == "--decode_hex") { + claim_hex := args[0] + decoded, err := claim.DecodeClaimHex(claim_hex) + if err != nil { + fmt.Println("Decoding error:", err) + return + } + text, err := decoded.RenderJSON() + if err != nil { + fmt.Println("Decoding error:", err) + return + } + fmt.Println(text) + return + } else { + fmt.Println("encountered an error\nusage: \n\tlbryschema-cli [--decode_hex]") + return + } +} diff --git a/main.go b/main.go deleted file mode 100644 index 850243e..0000000 --- a/main.go +++ /dev/null @@ -1,24 +0,0 @@ -package lbryschema_go - -import ( - "os" - "./claim" - "fmt" -) - -func main() { - args := os.Args[1:] - claim_hex := args[0] - decoded, err := claim.DecodeClaimHex(claim_hex) - if err != nil { - fmt.Println("Decoding error: ", err) - return - } - text, err := decoded.RenderJSON() - if err != nil { - fmt.Println("Decoding error: ", err) - return - } - fmt.Println(text) - return -}