util

package
v0.2.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 1, 2025 License: MIT Imports: 22 Imported by: 0

Documentation

Overview

Common utilities used by various subcommands

This file contains init methods that may be used by multiple sub-commands. For instance, the cach and projects sub-commands both depend on a cache and may both call the initProjectCache func (u *Util) from their PersistentPreRun commands

Index

Constants

View Source
const (
	// Cobra Flags
	FlagRemote     = "remote"
	FlagConfig     = "config"
	FlagPath       = "projectPath"
	FlagLogLevel   = "logLevel"
	FlagProjectID  = "projectID"
	FlagCacheForce = "force"
	FlagOwnerOnly  = "ownerOnly"
	FlagAll        = "all"
	FlagCurrent    = "current"
	FlagPrompt     = "prompt"
	FlagWrite      = "write"
	FlagSensitive  = "sensitive"
	FlagDocsPath   = "docsPath"

	// Viper config bindings
	ViperAliasAddPID        = "alias.add.projectID"
	ViperCacheUnlockForce   = "cache.unlock.force"
	ViperCacheLoadOwnerOnly = "cache.load.ownerOnly"
	ViperProjectListAll     = "project.list.all"
	ViperProjectShowCurrent = "project.show.current"
)
View Source
const (
	DefGitlabHost    = "https://gitlab.com"
	DefLogLevel      = "info"
	DefConfigPath    = "~/.config/git-project-manager.yaml"
	ConfigName       = "git-project-manager"
	LegacyConfigName = "gitlab-project-manager"
)
View Source
const AliasAddCmdLong = `Adds a project alias to a project
project ID can be provided, or will otherwise use fuzzy find`
View Source
const AliasCmdLong = `Manages project aliases, with options for
listing, adding, and deleting.`
View Source
const AliasDeleteCmdLong = `Deletes aliases from projects
project ID can be provided, or will otherwise use fuzzy find`
View Source
const AliasListCmdLong = `Lists all aliases by project`
View Source
const CacheCmdLong = `` /* 172-byte string literal not displayed */
View Source
const ConfigCmdLong = `Commands for managing configuration, particulary
useful for seeding a new config file`
View Source
const ConfigGenCmdLong = `Produces yaml to stdout that can be used
to seed the configuration file`
View Source
const ProjAddCmdLong = `Adds a new project to the local project path
uses fuzzy find to locate the project`
View Source
const ProjCmdLong = `Switches to a Git project by name or alias
If not found, will enter fzf mode. If not cloned, will clone
the project locally.`
View Source
const ProjGoCmdLong = `` /* 202-byte string literal not displayed */
View Source
const ProjListCmdLong = `List locally cloned projects. Optionally
lists all projects in project cache`
View Source
const ProjOpenCmdLong = `` /* 253-byte string literal not displayed */
View Source
const ProjRunCmdLong = `Runs the current project. Tries to detect
the language and runs accordingly (e.g. go run .)`
View Source
const ProjShowCmdLong = `Shows detail for a particular project
Will always fuzzy find`
View Source
const RootCmdLong = `` /* 175-byte string literal not displayed */
View Source
const UtilsKey utilsCtxKey = iota

Variables

This section is empty.

Functions

func AddToCtx

func AddToCtx(ctx context.Context, u *Utils) context.Context

func GetConfigName

func GetConfigName(configPath string) string

func InitProjects

func InitProjects(cmd *cobra.Command, args []string)

func PostProjectCmd

func PostProjectCmd(cmd *cobra.Command, args []string)

func ResolvePath

func ResolvePath(path string) (string, error)

func ValidAliasesFunc

func ValidAliasesFunc(cmd *cobra.Command, args []string, toComplete string) (
	[]string, cobra.ShellCompDirective,
)

func ValidLogLevelsFunc

func ValidLogLevelsFunc(_ *cobra.Command, _ []string, toComplete string) (
	[]string, cobra.ShellCompDirective,
)

func ValidProjectIdFunc

func ValidProjectIdFunc(cmd *cobra.Command, args []string, toComplete string) (
	[]string, cobra.ShellCompDirective,
)

func ValidProjectsFunc

func ValidProjectsFunc(cmd *cobra.Command, args []string, toComplete string) (
	[]string, cobra.ShellCompDirective,
)

func ValidRemotesFunc

func ValidRemotesFunc(cmd *cobra.Command, _ []string, toComplete string) (
	[]string, cobra.ShellCompDirective,
)

Types

type FzfProjectOpts

type FzfProjectOpts struct {
	Ctx           context.Context
	Search        string
	MustHaveAlias bool
	Remotes       []string
}

type UtilOpts

type UtilOpts struct {
	Ctx    context.Context
	Config *config.Config
	Logger *pterm.Logger
	Cache  *cache.Cache
}

type Utils

type Utils struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

func FromCtx

func FromCtx(ctx context.Context) (*Utils, error)

func MustFromCtx

func MustFromCtx(ctx context.Context) *Utils

func (*Utils) Cache

func (u *Utils) Cache() *cache.Cache

func (*Utils) Config

func (u *Utils) Config() *config.Config

func (*Utils) Context

func (u *Utils) Context() context.Context

func (*Utils) FilterProjectsWithRemotes

func (u *Utils) FilterProjectsWithRemotes(gitProjects []*projects.Project, remotes ...string) []*projects.Project

func (*Utils) FzfAliasFromAliases

func (u *Utils) FzfAliasFromAliases(opts *FzfProjectOpts, aliases []*cache.ProjectAlias) *cache.ProjectAlias

Given a list of aliases, will fuzzy-find and return a single one. Replaced by fzfProjectFromAliases in fzfSearchProjectAliases as merging is preferred, but can be used if it's ever desirable to return a single alias from all aliases

func (*Utils) FzfCwdOrSearchProjectAliases

func (u *Utils) FzfCwdOrSearchProjectAliases(opts *FzfProjectOpts) *projects.Project

If . is given as a project, will open project from the current working directory. Otherwise, will attempt to fuzzy-find a project given a search term if provided

func (*Utils) FzfFindProject

func (u *Utils) FzfFindProject(opts *FzfProjectOpts) *projects.Project

This will try to find a project by alias if a search term is given, otherwise will fuzzy find by project

func (*Utils) FzfPreviewWindow

func (u *Utils) FzfPreviewWindow(i, _, _ int) string

func (*Utils) FzfProject

func (u *Utils) FzfProject(opts *FzfProjectOpts) (*projects.Project, error)

If opts.MustHaveAlias, will only allow selection of projects that have at least one alias defined

func (*Utils) FzfProjectFromAliases

func (u *Utils) FzfProjectFromAliases(opts *FzfProjectOpts, aliases []*cache.ProjectAlias) (
	*projects.Project, error,
)

Given a list of aliases, merge them together and use the resulting list of projects to return a project

func (*Utils) FzfProjectFromProjects

func (u *Utils) FzfProjectFromProjects(opts *FzfProjectOpts, projects []*projects.Project) (
	*projects.Project, error,
)

Takes a list of projects and performs a fuzzyfind

func (*Utils) FzfSearchProjectAliases

func (u *Utils) FzfSearchProjectAliases(opts *FzfProjectOpts) *projects.Project

This will fuzzy search only aliases, preferring an exact match if one is given

func (*Utils) GetRemotes

func (u *Utils) GetRemotes(cmd *cobra.Command) *remotes.Remotes

Generically loads remotes from info.RemoteInfo in config.Remotes

func (*Utils) Init

func (u *Utils) Init(opts *UtilOpts)

func (*Utils) InitProjectCache

func (u *Utils) InitProjectCache(cmd *cobra.Command, _ []string)

func (*Utils) InitProjectPath

func (u *Utils) InitProjectPath(_ *cobra.Command, _ []string)

func (*Utils) Logger

func (u *Utils) Logger() *pterm.Logger

func (*Utils) PostProjectCache

func (u *Utils) PostProjectCache(_ *cobra.Command, _ []string)

func (*Utils) SearchStringFromArgs

func (u *Utils) SearchStringFromArgs(args []string) string

Nearly useless function that simply returns either an empty string, or a string from the first arg if one is provided

func (*Utils) SetCache

func (u *Utils) SetCache(c *cache.Cache)

func (*Utils) SetConfig

func (u *Utils) SetConfig(conf *config.Config)

func (*Utils) SetContext

func (u *Utils) SetContext(c context.Context)

func (*Utils) SetLogger

func (u *Utils) SetLogger(l *pterm.Logger)

func (*Utils) ValidProjectsOrAliasesFunc

func (u *Utils) ValidProjectsOrAliasesFunc(cmd *cobra.Command, args []string, toComplete string) (
	[]string, cobra.ShellCompDirective,
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL