Skip to content

Commit

Permalink
- [+] implement the business logic of cmd:x2j
Browse files Browse the repository at this point in the history
  • Loading branch information
suntong committed May 31, 2019
1 parent 9e3ed13 commit f44996d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -13,3 +13,4 @@
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
.glide/
jsonfiddle
jsonfiddle.exe
17 changes: 12 additions & 5 deletions cmd_x2j.go
Expand Up @@ -8,8 +8,11 @@ package main

import (
"fmt"
"io"
"os"

xj "github.com/basgys/goxml2json"

"github.com/mkideal/cli"
"github.com/mkideal/cli/clis"
)
Expand All @@ -24,15 +27,19 @@ func x2jCLI(ctx *cli.Context) error {
clis.Verbose(2, "<%s> -\n %+v\n %+v\n %v\n", ctx.Path(), rootArgv, argv, ctx.Args())
Opts.Compact, Opts.Prefix, Opts.Indent, Opts.Protect, Opts.Verbose =
rootArgv.Compact, rootArgv.Prefix, rootArgv.Indent, rootArgv.Protect, rootArgv.Verbose.Value()
// argv.Filei, argv.Fileo,
//return nil
return DoX2j()
// argv.Filei, argv.Fileo,

return DoX2j(argv.Filei, argv.Fileo)
}

//
// DoX2j implements the business logic of command `x2j`
func DoX2j() error {
func DoX2j(cin io.Reader, cout io.Writer) error {
fmt.Fprintf(os.Stderr, "%s v%s. x2j - XML to JSON\n", progname, version)
// fmt.Fprintf(os.Stderr, "Copyright (C) 2019, Tong Sun\n\n")

json, err := xj.Convert(cin)
abortOn("[::x2j] Convert from xml to json", err)

fmt.Fprintln(cout, json.String())
return nil
}
2 changes: 1 addition & 1 deletion jsonfiddle_main.go
Expand Up @@ -37,7 +37,7 @@ type OptsT struct {
var (
progname = "jsonfiddle"
// version tracks the release version.
version = "v0.5.0"
version = "0.5.0"
date = "2019-05-30"
)

Expand Down

0 comments on commit f44996d

Please sign in to comment.