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
- func AddToCtx(ctx context.Context, u *Utils) context.Context
- func GetConfigName(configPath string) string
- func InitProjects(cmd *cobra.Command, args []string)
- func PostProjectCmd(cmd *cobra.Command, args []string)
- func ResolvePath(path string) (string, error)
- func ValidAliasesFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
- func ValidLogLevelsFunc(_ *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective)
- func ValidProjectIdFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
- func ValidProjectsFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
- func ValidRemotesFunc(cmd *cobra.Command, _ []string, toComplete string) ([]string, cobra.ShellCompDirective)
- type FzfProjectOpts
- type UtilOpts
- type Utils
- func (u *Utils) Cache() *cache.Cache
- func (u *Utils) Config() *config.Config
- func (u *Utils) Context() context.Context
- func (u *Utils) FilterProjectsWithRemotes(gitProjects []*projects.Project, remotes ...string) []*projects.Project
- func (u *Utils) FzfAliasFromAliases(opts *FzfProjectOpts, aliases []*cache.ProjectAlias) *cache.ProjectAlias
- func (u *Utils) FzfCwdOrSearchProjectAliases(opts *FzfProjectOpts) *projects.Project
- func (u *Utils) FzfFindProject(opts *FzfProjectOpts) *projects.Project
- func (u *Utils) FzfPreviewWindow(i, _, _ int) string
- func (u *Utils) FzfProject(opts *FzfProjectOpts) (*projects.Project, error)
- func (u *Utils) FzfProjectFromAliases(opts *FzfProjectOpts, aliases []*cache.ProjectAlias) (*projects.Project, error)
- func (u *Utils) FzfProjectFromProjects(opts *FzfProjectOpts, projects []*projects.Project) (*projects.Project, error)
- func (u *Utils) FzfSearchProjectAliases(opts *FzfProjectOpts) *projects.Project
- func (u *Utils) GetRemotes(cmd *cobra.Command) *remotes.Remotes
- func (u *Utils) Init(opts *UtilOpts)
- func (u *Utils) InitProjectCache(cmd *cobra.Command, _ []string)
- func (u *Utils) InitProjectPath(_ *cobra.Command, _ []string)
- func (u *Utils) Logger() *pterm.Logger
- func (u *Utils) PostProjectCache(_ *cobra.Command, _ []string)
- func (u *Utils) SearchStringFromArgs(args []string) string
- func (u *Utils) SetCache(c *cache.Cache)
- func (u *Utils) SetConfig(conf *config.Config)
- func (u *Utils) SetContext(c context.Context)
- func (u *Utils) SetLogger(l *pterm.Logger)
- func (u *Utils) ValidProjectsOrAliasesFunc(cmd *cobra.Command, args []string, toComplete string) ([]string, cobra.ShellCompDirective)
Constants ¶
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" )
const ( DefGitlabHost = "https://gitlab.com" DefLogLevel = "info" DefConfigPath = "~/.config/git-project-manager.yaml" ConfigName = "git-project-manager" LegacyConfigName = "gitlab-project-manager" )
const AliasAddCmdLong = `Adds a project alias to a project
project ID can be provided, or will otherwise use fuzzy find`
const AliasCmdLong = `Manages project aliases, with options for
listing, adding, and deleting.`
const AliasDeleteCmdLong = `Deletes aliases from projects
project ID can be provided, or will otherwise use fuzzy find`
const AliasListCmdLong = `Lists all aliases by project`
const CacheCmdLong = `` /* 172-byte string literal not displayed */
const ConfigCmdLong = `Commands for managing configuration, particulary
useful for seeding a new config file`
const ConfigGenCmdLong = `Produces yaml to stdout that can be used
to seed the configuration file`
const ProjAddCmdLong = `Adds a new project to the local project path
uses fuzzy find to locate the project`
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.`
const ProjGoCmdLong = `` /* 202-byte string literal not displayed */
const ProjListCmdLong = `List locally cloned projects. Optionally
lists all projects in project cache`
const ProjOpenCmdLong = `` /* 253-byte string literal not displayed */
const ProjRunCmdLong = `Runs the current project. Tries to detect
the language and runs accordingly (e.g. go run .)`
const ProjShowCmdLong = `Shows detail for a particular project
Will always fuzzy find`
const RootCmdLong = `` /* 175-byte string literal not displayed */
const UtilsKey utilsCtxKey = iota
Variables ¶
This section is empty.
Functions ¶
func GetConfigName ¶
func InitProjects ¶
func PostProjectCmd ¶
func ResolvePath ¶
func ValidAliasesFunc ¶
func ValidLogLevelsFunc ¶
func ValidProjectIdFunc ¶
func ValidProjectsFunc ¶
func ValidRemotesFunc ¶
Types ¶
type FzfProjectOpts ¶
type Utils ¶
func MustFromCtx ¶
func (*Utils) FilterProjectsWithRemotes ¶
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 (*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 ¶
Generically loads remotes from info.RemoteInfo in config.Remotes
func (*Utils) SearchStringFromArgs ¶
Nearly useless function that simply returns either an empty string, or a string from the first arg if one is provided