github.com/suntong/cascadia@v1.3.0/cascadia_cliDef.go (about)

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