Refactor: apply new internal structurs #206
|
@ -19,12 +19,13 @@ import (
|
|||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Config reprensents local configurations
|
||||
// LocalConfig represents local configurations
|
||||
6543 marked this conversation as resolved
Outdated
|
||||
type LocalConfig struct {
|
||||
Logins []Login `yaml:"logins"`
|
||||
}
|
||||
|
||||
var (
|
||||
// Config contain if loaded local tea config
|
||||
Config LocalConfig
|
||||
yamlConfigPath string
|
||||
)
|
||||
|
@ -44,10 +45,12 @@ func init() {
|
|||
yamlConfigPath = filepath.Join(dir, "tea.yml")
|
||||
}
|
||||
|
||||
// GetConfigPath return path to tea config file
|
||||
func GetConfigPath() string {
|
||||
return yamlConfigPath
|
||||
}
|
||||
|
||||
// LoadConfig load config into global Config var
|
||||
func LoadConfig() error {
|
||||
ymlPath := GetConfigPath()
|
||||
exist, _ := utils.FileExist(ymlPath)
|
||||
|
@ -67,6 +70,7 @@ func LoadConfig() error {
|
|||
return nil
|
||||
}
|
||||
|
||||
// SaveConfig save config from global Config var into config file
|
||||
func SaveConfig() error {
|
||||
ymlPath := GetConfigPath()
|
||||
bs, err := yaml.Marshal(Config)
|
||||
|
@ -141,6 +145,8 @@ func curGitRepoPath(repoValue, remoteValue string) (*Login, string, error) {
|
|||
return nil, "", errors.New("No Gitea login found. You might want to specify --repo (and --login) to work outside of a repository")
|
||||
}
|
||||
|
||||
// GetOwnerAndRepo return repoOwner and repoName
|
||||
// based on relative path and default owner (if not in path)
|
||||
func GetOwnerAndRepo(repoPath, user string) (string, string) {
|
||||
if len(repoPath) == 0 {
|
||||
return "", ""
|
||||
|
|
|
@ -68,6 +68,7 @@ func (l *Login) GetSSHHost() string {
|
|||
return u.Hostname()
|
||||
}
|
||||
|
||||
// GetDefaultLogin return the default login
|
||||
func GetDefaultLogin() (*Login, error) {
|
||||
if len(Config.Logins) == 0 {
|
||||
return nil, errors.New("No available login")
|
||||
|
@ -81,6 +82,7 @@ func GetDefaultLogin() (*Login, error) {
|
|||
return &Config.Logins[0], nil
|
||||
}
|
||||
|
||||
// GetLoginByName get login by name
|
||||
func GetLoginByName(name string) *Login {
|
||||
for _, l := range Config.Logins {
|
||||
if l.Name == name {
|
||||
|
@ -90,6 +92,7 @@ func GetLoginByName(name string) *Login {
|
|||
return nil
|
||||
}
|
||||
|
||||
// AddLogin add a login to global Config var
|
||||
func AddLogin(login Login) error {
|
||||
for _, l := range Config.Logins {
|
||||
if l.Name == login.Name {
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/charmbracelet/glamour"
|
||||
)
|
||||
|
||||
// IssueDetails print an issue rendered to stdout
|
||||
func IssueDetails(issue *gitea.Issue) {
|
||||
|
||||
in := fmt.Sprintf("# #%d %s (%s)\n%s created %s\n\n%s\n", issue.Index,
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
// MilestoneDetails print an milestone formatted to stdout
|
||||
func MilestoneDetails(milestone *gitea.Milestone) {
|
||||
fmt.Printf("%s\n",
|
||||
milestone.Title,
|
||||
|
|
|
@ -17,8 +17,8 @@ func getGlamourTheme() string {
|
|||
return "light"
|
||||
}
|
||||
|
||||
// FormatSize get kb in int and return string
|
||||
func FormatSize(kb int64) string {
|
||||
// formatSize get kb in int and return string
|
||||
func formatSize(kb int64) string {
|
||||
if kb < 1024 {
|
||||
return fmt.Sprintf("%d Kb", kb)
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"github.com/charmbracelet/glamour"
|
||||
)
|
||||
|
||||
// PullDetails print an pull rendered to stdout
|
||||
func PullDetails(pr *gitea.PullRequest) {
|
||||
|
||||
in := fmt.Sprintf("# #%d %s (%s)\n%s created %s\n\n%s\n", pr.Index,
|
||||
|
|
|
@ -11,6 +11,7 @@ import (
|
|||
"code.gitea.io/sdk/gitea"
|
||||
)
|
||||
|
||||
// RepoDetails print an repo formatted to stdout
|
||||
func RepoDetails(repo *gitea.Repository, topics []string) {
|
||||
output := repo.FullName
|
||||
if repo.Mirror {
|
||||
|
@ -36,7 +37,7 @@ func RepoDetails(repo *gitea.Repository, topics []string) {
|
|||
repo.OpenIssues,
|
||||
repo.Stars,
|
||||
repo.Forks,
|
||||
FormatSize(int64(repo.Size)),
|
||||
formatSize(int64(repo.Size)),
|
||||
)
|
||||
|
||||
fmt.Print(output)
|
||||
|
|
Loading…
Reference in New Issue
Block a user
LocalConfig