More Options To Specify Repo #178
21
cmd/flags.go
21
cmd/flags.go
|
@ -7,6 +7,8 @@ package cmd
|
|||
import (
|
||||
"log"
|
||||
|
||||
"code.gitea.io/tea/modules/utils"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -81,16 +83,33 @@ var AllDefaultFlags = append([]cli.Flag{
|
|||
|
||||
// initCommand returns repository and *Login based on flags
|
||||
func initCommand() (*Login, string, string) {
|
||||
var (
|
||||
login *Login
|
||||
repoPath string
|
||||
)
|
||||
err := loadConfig(yamlConfigPath)
|
||||
if err != nil {
|
||||
log.Fatal("load config file failed ", yamlConfigPath)
|
||||
}
|
||||
|
||||
login, repoPath, err := curGitRepoPath(repoValue)
|
||||
if login, err = getActiveLogin(); err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
exist, err := utils.PathExists(repoValue)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
|
||||
if exist {
|
||||
login, repoPath, err = curGitRepoPath(repoValue)
|
||||
if err != nil {
|
||||
log.Fatal(err.Error())
|
||||
}
|
||||
} else {
|
||||
repoPath = repoValue
|
||||
}
|
||||
|
||||
if loginValue != "" {
|
||||
login = getLoginByName(loginValue)
|
||||
if login == nil {
|
||||
|
|
21
modules/utils/path.go
Normal file
21
modules/utils/path.go
Normal file
|
@ -0,0 +1,21 @@
|
|||
// Copyright 2020 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 utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
)
|
||||
|
||||
// PathExists returns whether the given file or directory exists or not
|
||||
func PathExists(path string) (bool, error) {
|
||||
_, err := os.Stat(path)
|
||||
if err == nil {
|
||||
return true, nil
|
||||
}
|
||||
if os.IsNotExist(err) {
|
||||
return false, nil
|
||||
}
|
||||
return true, err
|
||||
}
|
Loading…
Reference in New Issue
Block a user