forked from go-gitea/tea
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added global appendable Flags (go-gitea#12)
Signed-off-by: Andreas Ulm <[email protected]>
- Loading branch information
1 parent
9128037
commit 4a61afe
Showing
4 changed files
with
97 additions
and
79 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,84 @@ | ||
// Copyright 2019 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package cmd | ||
|
||
import ( | ||
"github.com/urfave/cli" | ||
"log" | ||
) | ||
|
||
// create global variables for global Flags to simplify | ||
// access to the options without requiring cli.Context | ||
var ( | ||
loginValue string | ||
repoValue string | ||
outputValue string | ||
) | ||
|
||
// LoginFlag provides flag to specify tea login profile | ||
var LoginFlag = cli.StringFlag{ | ||
Name: "login, l", | ||
Usage: "Indicate one login, optional when inside a gitea repository", | ||
Destination: &loginValue, | ||
} | ||
|
||
// RepoFlag provides flag to specify repository | ||
var RepoFlag = cli.StringFlag{ | ||
Name: "repo, r", | ||
Usage: "Indicate one repository, optional when inside a gitea repository", | ||
Destination: &repoValue, | ||
} | ||
|
||
// OutputFlag provides flag to specify output type | ||
var OutputFlag = cli.StringFlag{ | ||
Name: "output, o", | ||
Usage: "Indicate one repository, optional when inside a gitea repository", | ||
Destination: &outputValue, | ||
} | ||
|
||
// DefaultFlags defines flags that should be available | ||
// for all subcommands | ||
var DefaultFlags = []cli.Flag{ | ||
LoginFlag, | ||
OutputFlag, | ||
} | ||
|
||
// RepoDefaultFlags defines flags that should be available | ||
// for all subcommands working with dedicated repositories | ||
var RepoDefaultFlags = append([]cli.Flag{ | ||
RepoFlag, | ||
}, DefaultFlags...) | ||
|
||
// initCommand returns repository and *Login based on flags | ||
func initCommand() (*Login, string, string) { | ||
err := loadConfig(yamlConfigPath) | ||
if err != nil { | ||
log.Fatal("load config file failed", yamlConfigPath) | ||
} | ||
|
||
var login *Login | ||
if loginValue == "" { | ||
login, err = getActiveLogin() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} else { | ||
login = getLoginByName(loginValue) | ||
if login == nil { | ||
log.Fatal("indicated login name ", loginValue, " does not exist") | ||
} | ||
} | ||
|
||
repoPath := repoValue | ||
if repoPath == "" { | ||
login, repoPath, err = curGitRepoPath() | ||
if err != nil { | ||
log.Fatal(err.Error()) | ||
} | ||
} | ||
|
||
owner, repo := splitRepo(repoPath) | ||
return login, owner, repo | ||
} |
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