Skip to content

Commit

Permalink
adding request command, removing dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
coryb committed Aug 21, 2017
1 parent a1c2849 commit 56b1c9d
Show file tree
Hide file tree
Showing 6 changed files with 157 additions and 814 deletions.
286 changes: 5 additions & 281 deletions cmd/jira/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,11 @@ func main() {
Entry: cli.CmdBrowseRegistry(),
Aliases: []string{"b"},
},
jiracli.CommandRegistry{
Command: "request",
Entry: cli.CmdRequestRegistry(),
Aliases: []string{"req"},
},
}

cli.Register(app, registry)
Expand All @@ -270,285 +275,4 @@ func main() {
if err != nil {
log.Fatalf("%s", err)
}

// Usage:
// jira (b|browse) ISSUE
// jira request [-M METHOD] URI [DATA]
// jira ISSUE

// General Options:
// -b --browse Open your browser to the Jira issue
// -e --endpoint=URI URI to use for jira
// -k --insecure disable TLS certificate verification
// -h --help Show this usage
// -t --template=FILE Template file to use for output/editing
// -u --user=USER Username to use for authenticaion (default: %s)
// -v --verbose Increase output logging
// --unixproxy=PATH Path for a unix-socket proxy (eg., --unixproxy /tmp/proxy.sock)
// --version Print version

// Query Options:
// -a --assignee=USER Username assigned the issue
// -c --component=COMPONENT Component to Search for
// -f --queryfields=FIELDS Fields that are used in "list" template: (default: %s)
// -i --issuetype=ISSUETYPE The Issue Type
// -l --limit=VAL Maximum number of results to return in query (default: %d)
// --start=START Start parameter for pagination
// -p --project=PROJECT Project to Search for
// -q --query=JQL Jira Query Language expression for the search
// -r --reporter=USER Reporter to search for
// -s --sort=ORDER For list operations, sort issues (default: %s)

// Edit Options:
// -m --comment=COMMENT Comment message for transition
// -o --override=KEY=VAL Set custom key/value pairs

// Create Options:
// -i --issuetype=ISSUETYPE Jira Issue Type (default: Bug)
// -m --comment=COMMENT Comment message for transition
// -o --override=KEY=VAL Set custom key/value pairs

// Worklog Options:
// -T --time-spent=TIMESPENT Time spent working on issue
// -m --comment=COMMENT Comment message for worklog

// Command Options:
// -d --directory=DIR Directory to export templates to (default: %s)
// `, user, defaultQueryFields, defaultMaxResults, defaultSort, user, fmt.Sprintf("%s/.jira.d/templates", home))
// printer(output)
// }

// jiraCommands := map[string]string{
// "browse": "browse",
// "req": "request",
// "request": "request",
// }

// defaults := map[string]interface{}{
// "user": user,
// "queryfields": defaultQueryFields,
// "directory": fmt.Sprintf("%s/.jira.d/templates", home),
// "sort": defaultSort,
// "max_results": defaultMaxResults,
// "method": "GET",
// "quiet": false,
// }
// opts := make(map[string]interface{})

// setopt := func(name string, value interface{}) {
// opts[name] = value
// }

// op := optigo.NewDirectAssignParser(map[string]interface{}{
// "h|help": usage,
// "version": func() {
// fmt.Println(fmt.Sprintf("version: %s", jira.VERSION))
// os.Exit(0)
// },
// "v|verbose+": func() {
// logging.SetLevel(logging.GetLevel("")+1, "")
// },
// "dryrun": setopt,
// "b|browse": setopt,
// "editor=s": setopt,
// "u|user=s": setopt,
// "endpoint=s": setopt,
// "k|insecure": setopt,
// "t|template=s": setopt,
// "q|query=s": setopt,
// "p|project=s": setopt,
// "c|component=s": setopt,
// "a|assignee=s": setopt,
// "i|issuetype=s": setopt,
// "remove": setopt,
// "r|reporter=s": setopt,
// "f|queryfields=s": setopt,
// "x|expand=s": setopt,
// "s|sort=s": setopt,
// "l|limit|max_results=i": setopt,
// "start|start_at=i": setopt,
// "o|override=s%": &opts,
// "noedit": setopt,
// "edit": setopt,
// "m|comment=s": setopt,
// "d|dir|directory=s": setopt,
// "M|method=s": setopt,
// "S|saveFile=s": setopt,
// "T|time-spent=s": setopt,
// "Q|quiet": setopt,
// "unixproxy": setopt,
// "down": setopt,
// "default": setopt,
// })

// if err := op.ProcessAll(os.Args[1:]); err != nil {
// log.Errorf("%s", err)
// usage(false)
// }
// args := op.Args

// var command string
// if len(args) > 0 {
// if alias, ok := jiraCommands[args[0]]; ok {
// command = alias
// args = args[1:]
// } else if len(args) > 1 {
// // look at second arg for "dups" and "blocks" commands
// // also for 'set/add/remove' actions like 'labels'
// if alias, ok := jiraCommands[args[1]]; ok {
// command = alias
// args = append(args[:1], args[2:]...)
// }
// }
// }

// if command == "" && len(args) > 0 {
// command = args[0]
// args = args[1:]
// }

// os.Setenv("JIRA_OPERATION", command)
// loadConfigs(opts)

// // check to see if it was set in the configs:
// if value, ok := opts["command"].(string); ok {
// command = value
// } else if _, ok := jiraCommands[command]; !ok || command == "" {
// if command != "" {
// args = append([]string{command}, args...)
// }
// command = "view"
// }

// // apply defaults
// for k, v := range defaults {
// if _, ok := opts[k]; !ok {
// log.Debugf("Setting %q to %#v from defaults", k, v)
// opts[k] = v
// }
// }

// log.Debugf("opts: %v", opts)
// log.Debugf("args: %v", args)

// if _, ok := opts["endpoint"]; !ok {
// log.Errorf("endpoint option required. Either use --endpoint or set a endpoint option in your ~/.jira.d/config.yml file")
// os.Exit(1)
// }

// c := jira.New(opts)

// log.Debugf("opts: %s", opts)

// setEditing := func(dflt bool) {
// log.Debugf("Default Editing: %t", dflt)
// if dflt {
// if val, ok := opts["noedit"].(bool); ok && val {
// log.Debugf("Setting edit = false")
// opts["edit"] = false
// } else {
// log.Debugf("Setting edit = true")
// opts["edit"] = true
// }
// } else {
// if _, ok := opts["edit"].(bool); !ok {
// log.Debugf("Setting edit = %t", dflt)
// opts["edit"] = dflt
// }
// }
// }

// requireArgs := func(count int) {
// if len(args) < count {
// log.Errorf("Not enough arguments. %d required, %d provided", count, len(args))
// usage(false)
// }
// }

// var err error
// switch command {
// case "request":
// requireArgs(1)
// data := ""
// if len(args) > 1 {
// data = args[1]
// }
// err = c.CmdRequest(args[0], data)
// default:
// log.Errorf("Unknown command %s", command)
// os.Exit(1)
// }

// if err != nil {
// log.Errorf("%s", err)
// os.Exit(1)
// }
// os.Exit(0)
}

// func parseYaml(file string, opts map[string]interface{}) {
// if fh, err := ioutil.ReadFile(file); err == nil {
// log.Debugf("Found Config file: %s", file)
// if err := yaml.Unmarshal(fh, &opts); err != nil {
// log.Errorf("Unable to parse %s: %s", file, err)
// }
// }
// }

// func populateEnv(opts map[string]interface{}) {
// for k, v := range opts {
// envName := fmt.Sprintf("JIRA_%s", strings.ToUpper(k))
// var val string
// switch t := v.(type) {
// case string:
// val = t
// case int, int8, int16, int32, int64:
// val = fmt.Sprintf("%d", t)
// case float32, float64:
// val = fmt.Sprintf("%f", t)
// case bool:
// val = fmt.Sprintf("%t", t)
// default:
// val = fmt.Sprintf("%v", t)
// }
// os.Setenv(envName, val)
// }
// }

// func loadConfigs(opts map[string]interface{}) {
// populateEnv(opts)
// paths := jira.FindParentPaths(".jira.d/config.yml")
// // prepend
// paths = append(paths, "/etc/go-jira.yml")

// // iterate paths in reverse
// for i := 0; i < len(paths); i++ {
// file := paths[i]
// if stat, err := os.Stat(file); err == nil {
// tmp := make(map[string]interface{})
// // check to see if config file is exectuable
// if stat.Mode()&0111 == 0 {
// parseYaml(file, tmp)
// } else {
// log.Debugf("Found Executable Config file: %s", file)
// // it is executable, so run it and try to parse the output
// cmd := exec.Command(file)
// stdout := bytes.NewBufferString("")
// cmd.Stdout = stdout
// cmd.Stderr = bytes.NewBufferString("")
// if err := cmd.Run(); err != nil {
// log.Errorf("%s is exectuable, but it failed to execute: %s\n%s", file, err, cmd.Stderr)
// os.Exit(1)
// }
// yaml.Unmarshal(stdout.Bytes(), &tmp)
// }
// for k, v := range tmp {
// if _, ok := opts[k]; !ok {
// log.Debugf("Setting %q to %#v from %s", k, v, file)
// opts[k] = v
// }
// }
// populateEnv(opts)
// }
// }
// }
Loading

0 comments on commit 56b1c9d

Please sign in to comment.