fix InitCommand() (#285)

split modules/config

login_tasks.go should probably be modules/task/login.go,
but i didn't do that, as it still depends on the global
`Config` variable from the config module, see
https://gitea.com/gitea/tea/issues/158

rework InitCommand()

- make it error tolerant if $PWD is not a git repo (#200)
- don't force default login when repo flag is set (#191)

remove InitCommandLoginOnly()

Merge branch 'master' into issue-200-initcommand

improve docs

Merge branch 'master' into issue-200-initcommand

move config func and config task func to right place

Co-authored-by: Norwin Roosen <git@nroo.de>
Co-authored-by: 6543 <6543@obermui.de>
Reviewed-on: https://gitea.com/gitea/tea/pulls/285
Reviewed-by: 6543 <6543@obermui.de>
Reviewed-by: khmarbaise <khmarbaise@noreply.gitea.io>
Co-Authored-By: Norwin <noerw@noreply.gitea.io>
Co-Committed-By: Norwin <noerw@noreply.gitea.io>
This commit is contained in:
Norwin
2020-12-11 17:07:29 +08:00
committed by 6543
parent a91168fd36
commit 7e191eb18b
13 changed files with 333 additions and 323 deletions

View File

@ -34,7 +34,7 @@ var LoginFlag = cli.StringFlag{
var RepoFlag = cli.StringFlag{
Name: "repo",
Aliases: []string{"r"},
Usage: "Repository to interact with. Optional",
Usage: "Override local repository path or gitea repository slug to interact with. Optional",
Destination: &GlobalRepoValue,
}

View File

@ -47,6 +47,8 @@ func runNotifications(ctx *cli.Context) error {
var news []*gitea.NotificationThread
var err error
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
listOpts := flags.GetListOptions(ctx)
if listOpts.Page == 0 {
listOpts.Page = 1
@ -61,13 +63,11 @@ func runNotifications(ctx *cli.Context) error {
}
if ctx.Bool("all") {
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
news, _, err = login.Client().ListNotifications(gitea.ListNotificationOptions{
ListOptions: listOpts,
Status: status,
})
} else {
login, owner, repo := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
news, _, err = login.Client().ListRepoNotifications(owner, repo, gitea.ListNotificationOptions{
ListOptions: listOpts,
Status: status,

View File

@ -24,8 +24,7 @@ var CmdOrganizationDelete = cli.Command{
// RunOrganizationDelete delete user organization
func RunOrganizationDelete(ctx *cli.Context) error {
//TODO: Reconsider the usage InitCommandLoginOnly related to #200
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
client := login.Client()

View File

@ -30,8 +30,7 @@ var CmdOrganizationList = cli.Command{
// RunOrganizationList list user organizations
func RunOrganizationList(ctx *cli.Context) error {
//TODO: Reconsider the usage InitCommandLoginOnly related to #200
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
client := login.Client()

View File

@ -39,9 +39,9 @@ func runRepos(ctx *cli.Context) error {
}
func runRepoDetail(path string) error {
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
login, ownerFallback, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
client := login.Client()
repoOwner, repoName := utils.GetOwnerAndRepo(path, login.User)
repoOwner, repoName := utils.GetOwnerAndRepo(path, ownerFallback)
repo, _, err := client.GetRepo(repoOwner, repoName)
if err != nil {
return err

View File

@ -83,7 +83,7 @@ var CmdRepoCreate = cli.Command{
}
func runRepoCreate(ctx *cli.Context) error {
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
client := login.Client()
var (
repo *gitea.Repository

View File

@ -45,7 +45,7 @@ var CmdReposList = cli.Command{
// RunReposList list repositories
func RunReposList(ctx *cli.Context) error {
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
client := login.Client()
typeFilter, err := getTypeFilter(ctx)

View File

@ -57,7 +57,7 @@ var CmdReposSearch = cli.Command{
}
func runReposSearch(ctx *cli.Context) error {
login := config.InitCommandLoginOnly(flags.GlobalLoginValue)
login, _, _ := config.InitCommand(flags.GlobalRepoValue, flags.GlobalLoginValue, flags.GlobalRemoteValue)
client := login.Client()
var ownerID int64