-
Notifications
You must be signed in to change notification settings - Fork 11
/
cascadia_cliDef.go
110 lines (91 loc) · 3.68 KB
/
cascadia_cliDef.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
////////////////////////////////////////////////////////////////////////////
// Program: cascadiaC
// Purpose: cascadia wrapper
// Authors: Tong Sun (c) 2016-2023, All rights reserved
////////////////////////////////////////////////////////////////////////////
package main
import (
// "fmt"
// "os"
"github.com/mkideal/cli"
// "github.com/mkideal/cli/clis"
clix "github.com/mkideal/cli/ext"
)
////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions
//==========================================================================
// cascadiaC
type rootT struct {
cli.Helper
Filei *clix.Reader `cli:"*i,in" usage:"The html/xml file to read from (or stdin)"`
Fileo *clix.Writer `cli:"*o,out" usage:"The output file (or stdout)"`
CSS []string `cli:"*c,css" usage:"CSS selectors (can provide more if not using --piece)"`
TextOut bool `cli:"t,text" usage:"Text output for none-block selection mode"`
TextRaw bool `cli:"R,Raw" usage:"Raw text output, no trimming of leading and trailing white space"`
Piece PieceStyleMap `cli:"p,piece" usage:"sub CSS selectors within -css to split that block up into pieces\n\t\t\tformat: PieceName=[PieceStyle:]selector_string\n\t\t\t PieceStyle:\n\t\t\t RAW : will return the selected as-is\n\t\t\t ATTR : will return the value of attribute selector_string\n\t\t\t Else the text will be returned"`
Deli string `cli:"d,delimiter" usage:"delimiter for pieces csv output" dft:"\t"`
WrapHTML bool `cli:"w,wrap-html" usage:"wrap up the output with html tags"`
Style string `cli:"y,style" usage:"style component within the wrapped html head"`
Base string `cli:"b,base" usage:"base href tag used in the wrapped up html"`
Quiet bool `cli:"q,quiet" usage:"be quiet"`
}
var root = &cli.Command{
Name: "cascadiaC",
Desc: "cascadia wrapper\nVersion " + version + " built on " + date +
"\nCopyright (C) 2016-2023, Tong Sun",
Text: "Command line interface to go cascadia CSS selectors package" +
"\n\nUsage:\n cascadia -i in -c css -o [Options...]",
Argv: func() interface{} { return new(rootT) },
Fn: CascadiaC,
NumOption: cli.AtLeast(3),
}
// Template for main starts here
////////////////////////////////////////////////////////////////////////////
// Constant and data type/structure definitions
// The OptsT type defines all the configurable options from cli.
// type OptsT struct {
// Filei *clix.Reader
// Fileo *clix.Writer
// CSS []string
// TextOut bool
// TextRaw bool
// Piece PieceStyleMap
// Deli string
// WrapHTML bool
// Style string
// Base string
// Quiet bool
// Verbose int
// }
////////////////////////////////////////////////////////////////////////////
// Global variables definitions
// var (
// progname = "cascadiaC"
// version = "0.1.0"
// date = "2023-06-29"
// rootArgv *rootT
// // Opts store all the configurable options
// Opts OptsT
// )
////////////////////////////////////////////////////////////////////////////
// Function definitions
// Function main
// func main() {
// cli.SetUsageStyle(cli.DenseNormalStyle)
// if err := cli.Root(root,).Run(os.Args[1:]); err != nil {
// fmt.Fprintln(os.Stderr, err)
// os.Exit(1)
// }
// fmt.Println("")
// }
// Template for main dispatcher starts here
//==========================================================================
// Dumb root handler
// CascadiaC - main dispatcher dumb handler
// func CascadiaC(ctx *cli.Context) error {
// ctx.JSON(ctx.RootArgv())
// ctx.JSON(ctx.Argv())
// fmt.Println()
// return nil
// }
// Template for CLI handling starts here