-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create common interface for wapty commands
- Loading branch information
1 parent
072194e
commit 0023e9a
Showing
5 changed files
with
100 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package common | ||
|
||
import ( | ||
"flag" | ||
"fmt" | ||
"os" | ||
) | ||
|
||
// Command is used by any package exposing a runnable command to gather information | ||
// about command name, usage and flagset. | ||
type Command struct { | ||
Name string | ||
Run func() | ||
UsageLine string | ||
Short string | ||
Long string | ||
Flag flag.FlagSet | ||
} | ||
|
||
func (c *Command) Usage() { | ||
fmt.Fprintf(os.Stderr, "usage: %s\n\n", c.UsageLine) | ||
c.Flag.PrintDefaults() | ||
os.Exit(2) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package decode | ||
|
||
import "github.com/empijei/wapty/common" | ||
|
||
var CmdDecode = common.Command{ | ||
Name: "decode", | ||
Run: MainStandalone, | ||
UsageLine: "decode [flags]", | ||
Short: "decode something.", | ||
Long: `decode something in a really clever way: | ||
blah blah blah | ||
`, | ||
} | ||
|
||
var flagEncode bool // -encode | ||
var flagCodeclist string // -codec | ||
|
||
func init() { | ||
CmdDecode.Flag.BoolVar(&flagEncode, "encode", false, "Sets the decoder to an encoder instead") | ||
CmdDecode.Flag.StringVar(&flagCodeclist, "codec", "smart", | ||
`Sets the decoder/encoder codec. Multiple codecs can be specified and comma separated: | ||
they will be applied one on the output of the previous as in a pipeline. | ||
`) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters