Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f44996d

Browse files
committed
- [+] implement the business logic of cmd:x2j
1 parent 9e3ed13 commit f44996d

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

‎.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@
1313
# Project-local glide cache, RE: https://github.com/Masterminds/glide/issues/736
1414
.glide/
1515
jsonfiddle
16+
jsonfiddle.exe

‎cmd_x2j.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,11 @@ package main
88

99
import (
1010
"fmt"
11+
"io"
1112
"os"
1213

14+
xj "github.com/basgys/goxml2json"
15+
1316
"github.com/mkideal/cli"
1417
"github.com/mkideal/cli/clis"
1518
)
@@ -24,15 +27,19 @@ func x2jCLI(ctx *cli.Context) error {
2427
clis.Verbose(2, "<%s> -\n %+v\n %+v\n %v\n", ctx.Path(), rootArgv, argv, ctx.Args())
2528
Opts.Compact, Opts.Prefix, Opts.Indent, Opts.Protect, Opts.Verbose =
2629
rootArgv.Compact, rootArgv.Prefix, rootArgv.Indent, rootArgv.Protect, rootArgv.Verbose.Value()
27-
// argv.Filei, argv.Fileo,
28-
//return nil
29-
return DoX2j()
30+
// argv.Filei, argv.Fileo,
31+
32+
return DoX2j(argv.Filei, argv.Fileo)
3033
}
3134

32-
//
3335
// DoX2j implements the business logic of command `x2j`
34-
func DoX2j() error {
36+
func DoX2j(cin io.Reader, cout io.Writer) error {
3537
fmt.Fprintf(os.Stderr, "%s v%s. x2j - XML to JSON\n", progname, version)
3638
// fmt.Fprintf(os.Stderr, "Copyright (C) 2019, Tong Sun\n\n")
39+
40+
json, err := xj.Convert(cin)
41+
abortOn("[::x2j] Convert from xml to json", err)
42+
43+
fmt.Fprintln(cout, json.String())
3744
return nil
3845
}

‎jsonfiddle_main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ type OptsT struct {
3737
var (
3838
progname = "jsonfiddle"
3939
// version tracks the release version.
40-
version = "v0.5.0"
40+
version = "0.5.0"
4141
date = "2019年05月30日"
4242
)
4343

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /