Documentation ¶
Index ¶
- Constants
- Variables
- func CaptureStdout(f func()) string
- func CreateParentDir(path string) error
- func GivesStringAsStdin(inputFromStdin string, f func())
- func HumanizeTime(time time.Time) string
- func IsExistAndGitRepository(absPath string, path string) error
- func IsInputYes(prompt string) bool
- func ReplaceNewline(originalString, replaceTo string) string
- func Rollback(dbFile, configFile string, f func(config *Config, db *Database)) string
- func Strftime(time time.Time, config *Config) string
- type Color
- func (c *Color) ClearColorize()
- func (c *Color) ColorizeConfigValue(value string) string
- func (c *Color) ColorizedGroupName(groupName string) string
- func (c *Color) ColorizedLabel(label string) string
- func (c *Color) ColorizedRepositoryID(repoID string) string
- func (c *Color) SetColorize(enable bool)
- type Config
- func (config *Config) GetDefaultValue(label string) string
- func (config *Config) GetString(label string) (string, ReadFrom)
- func (config *Config) GetValue(label string) string
- func (config *Config) IsSet(label string) bool
- func (config *Config) PrintErrors(errs ...error) int
- func (config *Config) StoreConfig() error
- func (config *Config) Unset(label string) error
- func (config *Config) Update(label string, value string) error
- type Database
- func (db *Database) AutoCreateGroup(groupID string, description string, omitList bool) (*Group, error)
- func (db *Database) BelongingCount(repoID string) int
- func (db *Database) ContainsCount(groupID string) int
- func (db *Database) CreateGroup(groupID string, description string, omitList bool) (*Group, error)
- func (db *Database) CreateRepository(repoID string, path string, desc string, remotes []Remote) (*Repository, error)
- func (db *Database) DeleteGroup(groupID string) error
- func (db *Database) DeleteRepository(repoID string) error
- func (db *Database) FindGroup(groupID string) *Group
- func (db *Database) FindRelationsOfGroup(groupID string) []string
- func (db *Database) FindRelationsOfRepository(repositoryID string) []string
- func (db *Database) FindRepository(repoID string) *Repository
- func (db *Database) ForceDeleteGroup(groupID string) error
- func (db *Database) HasGroup(groupID string) bool
- func (db *Database) HasRelation(groupID string, repoID string) bool
- func (db *Database) HasRepository(repoID string) bool
- func (db *Database) Prune() (int, int)
- func (db *Database) PruneTargets() ([]Repository, []Group)
- func (db *Database) Relate(groupID string, repoID string) error
- func (db *Database) StoreAndClose() error
- func (db *Database) Unrelate(groupID string, repoID string)
- func (db *Database) UnrelateFromGroup(groupID string)
- func (db *Database) UnrelateRepository(repoID string)
- func (db *Database) UpdateGroup(groupID string, newGroup Group) bool
- func (db *Database) UpdateRepository(repositoryID string, newRepo Repository) bool
- type Group
- type LogLevel
- type MessageCenter
- func (mc *MessageCenter) FindMessages(level LogLevel) []string
- func (mc *MessageCenter) Print(out io.Writer, level LogLevel)
- func (mc *MessageCenter) PrintLog(out io.Writer)
- func (mc *MessageCenter) PrintVerbose(out io.Writer)
- func (mc *MessageCenter) Push(message string, level LogLevel)
- func (mc *MessageCenter) PushLog(message string)
- func (mc *MessageCenter) PushVerbose(message string)
- type ReadFrom
- type Relation
- type Remote
- type Repository
- type RrhTime
- type Status
- type StatusOption
Examples ¶
Constants ¶
const ( AutoDeleteGroup = "RRH_AUTO_DELETE_GROUP" AutoCreateGroup = "RRH_AUTO_CREATE_GROUP" CloneDestination = "RRH_CLONE_DESTINATION" ColorSetting = "RRH_COLOR" ConfigPath = "RRH_CONFIG_PATH" DatabasePath = "RRH_DATABASE_PATH" DefaultGroupName = "RRH_DEFAULT_GROUP_NAME" EnableColorized = "RRH_ENABLE_COLORIZED" Home = "RRH_HOME" OnError = "RRH_ON_ERROR" SortOnUpdating = "RRH_SORT_ON_UPDATING" TimeFormat = "RRH_TIME_FORMAT" )
The environment variable names.
const ( Default = "default" ConfigFile = "config_file" Env = "environment" NotFound = "not found" )
The the 2nd return value of GetString method (ReadFrom).
const ( Fail = "FAIL" FailImmediately = "FAIL_IMMEDIATELY" Warn = "WARN" Ignore = "IGNORE" )
The values of RrhOnError.
const Relative = "relative"
Relative shows the default value of RrhTimeFormat.
const VERSION = "1.2.0"
VERSION shows the version of RRH.
Variables ¶
var AvailableLabels = []string{ AutoCreateGroup, AutoDeleteGroup, CloneDestination, ColorSetting, ConfigPath, DatabasePath, DefaultGroupName, EnableColorized, Home, OnError, SortOnUpdating, TimeFormat, }
AvailableLabels represents the labels availables in the config.
Functions ¶
func CaptureStdout ¶
func CaptureStdout(f func()) string
CaptureStdout is referred from https://qiita.com/kami_zh/items/ff636f15da87dabebe6c.
func CreateParentDir ¶
CreateParentDir create the parent directories of the given path.
func GivesStringAsStdin ¶
func GivesStringAsStdin(inputFromStdin string, f func())
GivesStringAsStdin treats given inputFromStdin string as a byte stream from stdin.
func HumanizeTime ¶
HumanizeTime convert the given time to human friendly formatted string.
func IsExistAndGitRepository ¶
IsExistAndGitRepository checks the given absPath is exist and shows the git repository.
func IsInputYes ¶
IsInputYes print the given prompt and returns TRUE if the user inputs "yes".
func ReplaceNewline ¶
ReplaceNewline trims spaces and converts the return codes in `originalString` to `replaceTo` string.
Types ¶
type Color ¶
type Color struct {
// contains filtered or unexported fields
}
Color struct shows the color settings of RRH.
func InitializeColor ¶
InitializeColor is the initialization function of the colorized output. The function is automatically called on loading the config file.
func (*Color) ClearColorize ¶
func (c *Color) ClearColorize()
ClearColorize clears the color settings.
func (*Color) ColorizeConfigValue ¶
ColorizeConfigValue returns the coloried config value from configuration.
func (*Color) ColorizedGroupName ¶
ColorizedGroupName returns the colorized group name string from configuration.
func (*Color) ColorizedLabel ¶
ColorizedLabel returns the colorized label string from configuration.
func (*Color) ColorizedRepositoryID ¶
ColorizedRepositoryID returns the colorized repository id string from configuration.
func (*Color) SetColorize ¶
SetColorize sets to enable colorization.
type Config ¶
type Config struct { Color *Color // contains filtered or unexported fields }
Config shows the values of configuration variables.
func OpenConfig ¶
func OpenConfig() *Config
OpenConfig reads the config file and returns it. The load path is based on `RrhConfigPath` of the environment variables.
func (*Config) GetDefaultValue ¶
GetDefaultValue returns the default value of the given variable name.
func (*Config) GetString ¶
GetString returns the value of the given variable name and the definition part of the value.
func (*Config) IsSet ¶
IsSet returns the bool value of the given label. If the label is not RrhAutoCreateGroup, RrhAutoDeleteGroup, and RrhSortOnUpdating, this method always returns false.
func (*Config) PrintErrors ¶
PrintErrors prints errors and returns the status code by following the value of RrhOnError. If the value of RrhOnError is Ignore or Warn, this method returns 0, otherwise, non-zero value.
type Database ¶
type Database struct { Timestamp RrhTime `json:"last_modified"` Repositories []Repository `json:"repositories"` Groups []Group `json:"groups"` Relations []Relation `json:"relations"` Config *Config `json:"-"` }
Database represents the whole database of RRH.
func Open ¶
Open function is to read rrh database from a certain path.
How to call this function
var db *Database db = common.Open()
func (*Database) AutoCreateGroup ¶
func (db *Database) AutoCreateGroup(groupID string, description string, omitList bool) (*Group, error)
AutoCreateGroup returns the group by creating the given parameters and store it to the database by satisfying the config value of RrhAutoCreateGroup is true.
func (*Database) BelongingCount ¶
BelongingCount returns the number of groups belonging given repoID.
func (*Database) ContainsCount ¶
ContainsCount returns the number of repositories in the given groupID.
func (*Database) CreateGroup ¶
CreateGroup returns the group by creating the given parameters and store it to database. If db has the group with the given groupID, this method returns error.
func (*Database) CreateRepository ¶
func (db *Database) CreateRepository(repoID string, path string, desc string, remotes []Remote) (*Repository, error)
CreateRepository returns the repository by creating the given parameters and store it to database.
func (*Database) DeleteGroup ¶
DeleteGroup removes the group of the given groupId from DB. If the group has some repositories, the function fails to remove.
func (*Database) DeleteRepository ¶
DeleteRepository function removes the repository of given repoID from DB. Also, the relation between the repository and groups are removed.
func (*Database) FindRelationsOfGroup ¶
FindRelationsOfGroup returns the repository ids belonging to the specified group.
func (*Database) FindRelationsOfRepository ¶
FindRelationsOfRepository returns the group names of the specified repository.
func (*Database) FindRepository ¶
func (db *Database) FindRepository(repoID string) *Repository
FindRepository returns the repository which ID is given `repoID.`
func (*Database) ForceDeleteGroup ¶
ForceDeleteGroup removes the group of the given groupID from DB. Even if the group has some repositories, the function forcely remove the group.
func (*Database) HasRelation ¶
HasRelation returns true if the group and the repository has relation. The group and the repository are specified by the given parameters.
func (*Database) HasRepository ¶
HasRepository returns true if the db has the repository of repoID.
func (*Database) PruneTargets ¶
func (db *Database) PruneTargets() ([]Repository, []Group)
PruneTargets returns the pruned (unnecessary) repositories and groups from db.
func (*Database) Relate ¶
Relate create the relation between the group and the repository. The group and the repository are specified by the given parameters. If the group and the repository have the relation, this function returns `nil` (successfully create relation).
func (*Database) StoreAndClose ¶
StoreAndClose stores the database to file and close the database. The database path is defined in RRH_DATABASE_PATH of config.
func (*Database) Unrelate ¶
Unrelate deletes the relation between the group and the repository. The group and the repository are specified by the given parameters. If the group and the repository do not have the relation, this function returns `nil` (successfully delete relation).
func (*Database) UnrelateFromGroup ¶
UnrelateFromGroup deletes all relations about the specified group.
func (*Database) UnrelateRepository ¶
UnrelateRepository deletes all relations of the specified repository.
func (*Database) UpdateGroup ¶
UpdateGroup updates found group with `newGroupID` and `newDescription`. The return value is that the update is success or not.
func (*Database) UpdateRepository ¶
func (db *Database) UpdateRepository(repositoryID string, newRepo Repository) bool
UpdateRepository updates the repository information.
type Group ¶
type Group struct { Name string `json:"group_name"` Description string `json:"group_desc"` OmitList bool `json:"omit_list"` }
Group represents the groups of the Git repositories.
type MessageCenter ¶
type MessageCenter struct {
// contains filtered or unexported fields
}
MessageCenter manages log entries.
Example ¶
var mc = NewMessageCenter() mc.PushLog("info level") mc.PushVerbose("verbose level") mc.Push("warn level", WARN) mc.Push("severe level", SEVERE) mc.PrintLog(os.Stdout)
Output: info level warn level severe level
func NewMessageCenter ¶
func NewMessageCenter() *MessageCenter
NewMessageCenter creates an instance of MessageCenter.
func (*MessageCenter) FindMessages ¶
func (mc *MessageCenter) FindMessages(level LogLevel) []string
FindMessages returns messages in the receiver MessageCenter with greater than given log level.
func (*MessageCenter) Print ¶
func (mc *MessageCenter) Print(out io.Writer, level LogLevel)
Print prints greater than given level messages in the receiver MessageCenter to the given writer.
func (*MessageCenter) PrintLog ¶
func (mc *MessageCenter) PrintLog(out io.Writer)
PrintLog prints messages of INFO, WARN, and SEVERE log level in the receiver MessageCenter to the given writer.
func (*MessageCenter) PrintVerbose ¶
func (mc *MessageCenter) PrintVerbose(out io.Writer)
PrintVerbose prints messages of VERBOSE, INFO, WARN, and SEVERE log level in the receiver MessageCenter to the given writer.
func (*MessageCenter) Push ¶
func (mc *MessageCenter) Push(message string, level LogLevel)
Push append given message to receiver MessageCenter as given level.
func (*MessageCenter) PushLog ¶
func (mc *MessageCenter) PushLog(message string)
PushLog append given message to receiver MessageCenter as INFO level.
func (*MessageCenter) PushVerbose ¶
func (mc *MessageCenter) PushVerbose(message string)
PushVerbose append given message to receiver MessageCenter as VERBOSE level.
type ReadFrom ¶
type ReadFrom string
ReadFrom shows the value of config load from. The available values are default, config_file, environment, and not found.
type Relation ¶
type Relation struct { RepositoryID string `json:"repository_id"` GroupName string `json:"group_name"` }
Relation represents the relation between group and the repository.
func FindTargets ¶
FindTargets returns instances of Relation objects with given groupNames.
type Remote ¶
Remote represents remote of the git repository.
func FindRemotes ¶
FindRemotes function returns the remote of the given git repository.
type Repository ¶
type Repository struct { ID string `json:"repository_id"` Path string `json:"repository_path"` Description string `json:"repository_desc"` Remotes []Remote `json:"remotes"` }
Repository represents a Git repository.
type RrhTime ¶
type RrhTime struct {
// contains filtered or unexported fields
}
RrhTime represents the time for RRH command, for marshaling a specific format.
func (RrhTime) MarshalJSON ¶
MarshalJSON is called on marshaling JSON.
func (*RrhTime) UnmarshalJSON ¶
UnmarshalJSON is called on unmarshaling JSON.
type Status ¶
type Status struct { Relation *Relation BranchName string LastModified *time.Time Description string }
Status shows the result of the `rrh status` command.
type StatusOption ¶
StatusOption represents for getting status of branches in a repository.
func NewStatusOption ¶
func NewStatusOption() *StatusOption
NewStatusOption generates an instance of StatusOption.
func (*StatusOption) StatusOfRepository ¶
func (status *StatusOption) StatusOfRepository(db *Database, name *Relation) ([]Status, error)
StatusOfRepository returns statuses of a given repository.