This repository was archived by the owner on May 24, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 27
added global appendable Flags (#12) #26
Open
root360-AndreasUlm
wants to merge
5
commits into
go-gitea:master
Choose a base branch
from
root360-AndreasUlm:12_global_cli_flags
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4a61afe
added global appendable Flags (#12)
root360-AndreasUlm a16ca12
added description to explain reason for global variables
root360-AndreasUlm f7d5eb1
fixed package import definition
root360-AndreasUlm 724948c
fixed description of --output
root360-AndreasUlm 9a3898a
changed Flags of pulls & issues to RepoDefaultFlags only
root360-AndreasUlm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,88 @@ | ||
// 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 and appended to the flags of the | ||
// subcommand to work around issue: | ||
// https://github.com/urfave/cli/issues/585 | ||
var DefaultFlags = []cli.Flag{ | ||
LoginFlag, | ||
OutputFlag, | ||
} | ||
|
||
// RepoDefaultFlags defines flags that should be available | ||
// for all subcommands working with dedicated repositories | ||
// to work around issue: | ||
// https://github.com/urfave/cli/issues/585 | ||
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 hidden or 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 hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.