Documentation
¶
Overview ¶
* @Desc: environment and extensions loading. * @Author: TaceyWong * @Date: 2020-09-23 17:02:11 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 17:44:26
* All exceptions used in the Starter code base are defined here. * @Author: TaceyWong * @Date: 2020-09-23 17:00:44 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 17:30:34
* extensions. * @Author: TaceyWong * @Date: 2020-09-23 17:02:00 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 17:45:00
* Functions for generating a project from a project template. * @Author: TaceyWong * @Date: 2020-09-23 17:00:57 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 17:48:32
* Functions for discovering and executing various Starter hooks. * @Author: TaceyWong * @Date: 2020-09-23 16:58:43 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 18:07:34
* Module for setting up logging. * @Author: TaceyWong * @Date: 2020-09-23 17:01:33 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 19:25:29
* Functions for prompting the user for project info. * @Author: TaceyWong * @Date: 2020-09-23 16:59:15 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 19:24:56
* Replay Starter action * @Author: TaceyWong * @Date: 2020-09-23 16:59:26 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-27 14:50:38
* Starter repository functions. * @Author: TaceyWong * @Date: 2020-09-23 16:59:40 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 19:36:17
* @Author: TaceyWong * @Date: 2020-09-23 16:59:52 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 17:14:03
* Utility functions for handling and fetching repo archives in zip format * @Author: TaceyWong * @Date: 2020-09-23 17:00:26 * @Last Modified by: TaceyWong * @Last Modified time: 2020-09-23 18:12:04
Index ¶
- Constants
- Variables
- func Clone(repoURL string, checkout string, cloneToDir string, noInput bool) string
- func DetermineRepoDir(template, abbreviations, cloneToDir string, checkout, noInput bool, ...)
- func Dump(replayDir, templateName, context string)
- func Example()
- func ExpandAbbreviations(template, abbreviations string)
- func FindHook(hookName, hookDir string) []string
- func FindTemplate(repoDir string) string
- func GetConfig(configPath string) map[string]interface{}
- func GetFileName(replayDir, templateName string)
- func GetUserConfig(configFile string, deaultConfig bool) map[string]interface{}
- func IdentifyRepo(repoURL string) (string, string, error)
- func IsRepoURL(value string) bool
- func IsSlug(text string) bool
- func IsZipFile(value string) bool
- func Load(replayDir, templateName string)
- func Make(s string) (slug string)
- func MakeExecutable(scriptPath string)
- func MakeLang(s string, lang string) (slug string)
- func MakeSurePathExist(path string) bool
- func MergeConfigs(defaultC, overwriteC map[string]interface{}) map[string]interface{}
- func ProcessJSON(userValue string) (string, error)
- func PromptAndDelete(path string, noInput bool) bool
- func PromptChoiceForConfig(starterDict, env map[string]string, key string, options []string, noInput bool)
- func PromptForConfig(context string, noInput bool)
- func ReadRepoPassword(password *string, question string) string
- func ReadUserChoice(varName *string, question string, options []string) string
- func ReadUserDict(varName string, defaultValue string)
- func ReadUserVariable(msg string, varName *string, defaultValue string) string
- func ReadUserYesNo(confirm *bool, question string, defaultValue bool) bool
- func RenderVariable(env, raw string, starterDict map[string]string)
- func RepositoryHasStarterJSON(repoDirectory string) bool
- func RmTree(dirPath string)
- func RunHook(hookName, projectDir string, context interface{})
- func RunScript(scriptPath, cwd string)
- func RunScriptWithContext(scriptPath, cwd string, context interface{})
- func Substitute(s string, sub map[string]string) (buf string)
- func SubstituteRune(s string, sub map[rune]string) string
- func UnZip(cloneToDir string, noInput bool, password string) error
- func UnZipFromURL(zipURI string, isURL bool, cloneToDir string, noInput bool, password string) error
- func ValidHook(hookFile, hookName string) bool
- func WorkIn(dirname string)
- type ConfigDoesNotExistException
- type ContextDecodingException
- type FailedHookException
- type InvalidConfiguration
- type InvalidModeException
- type InvalidZipRepository
- type MissingProjectDir
- type NonTemplatedInputDirException
- type OutputDirExistsException
- type RepositoryCloneFailed
- type RepositoryNotFound
- type Starter
- type StarterException
- type StarterOption
- type UndefinedVariableInTemplate
- type UnknownExtension
- type UnknownRepoType
- type UnknownTemplateDirException
- type VCSNotInstalled
Constants ¶
const UserConfigPath string = ""
UserConfigPath location of user's config
Variables ¶
var ( // CustomSub stores custom substitution map CustomSub map[string]string // CustomRuneSub stores custom rune substitution map CustomRuneSub map[rune]string // MaxLength stores maximum slug length. // It's smart so it will cat slug after full word. // By default slugs aren't shortened. // If MaxLength is smaller than length of the first word, then returned // slug will contain only substring from the first word truncated // after MaxLength. MaxLength int // Lowercase defines if the resulting slug is transformed to lowercase. // Default is true. Lowercase = true )
var BuiltinAbbreviations = map[string]string{
"gh": "https://github.com/{0}.git",
"gl": "https://gitlab.com/{0}.git",
"bb": "https://bitbucket.org/{0}",
}
BuiltinAbbreviations built-in cvs format
var DefaultConfig = map[string]interface{}{ "starter_dir": "~/.starter/", "replay_dir": "~/.starter_replay/", "default_context": map[string][]string{}, "abbreviations": BuiltinAbbreviations, }
DefaultConfig Starter default config
var Hooks = []string{"pre_gen_project", "post_gen_project"}
var Regex = regexp.MustCompile(`((((git|hg)\+)?(git|ssh|file|https?):(//)?)|(\w+@[\w\.]+))`)
Regex something like git:// ssh:// file:// etc.
or something like user@...
Functions ¶
func Clone ¶
Clone Clone a repo to the current directory.
:param repo_url: Repo URL of unknown type. :param checkout: The branch, tag or commit ID to checkout after clone. :param clone_to_dir: The directory to clone to.
Defaults to the current directory.
:param no_input: Suppress all user prompts when calling via API.
func DetermineRepoDir ¶
func DetermineRepoDir(template, abbreviations, cloneToDir string, checkout, noInput bool, password, directory string)
DetermineRepoDir Locate the repository directory from a template reference.
Applies repository abbreviations to the template reference. If the template refers to a repository URL, clone it. If the template is a path to a local repository, use it.
:param template: A directory containing a project template directory,
or a URL to a git repository.
:param abbreviations: A dictionary of repository abbreviation definitions. :param clone_to_dir: The directory to clone the repository into. :param checkout: The branch, tag or commit ID to checkout after clone. :param no_input: Prompt the user at command line for manual configuration? :param password: The password to use when extracting the repository. :param directory: Directory within repo where starter.json lives. :return: A tuple containing the starter template directory, and
a boolean descriving whether that directory should be cleaned up after the template has been instantiated.
:raises: `RepositoryNotFound` if a repository directory could not be found.
func ExpandAbbreviations ¶
func ExpandAbbreviations(template, abbreviations string)
ExpandAbbreviations Expand abbreviations in a template name.
func FindHook ¶
FindHook Return a dict of all hook scripts provided.
Must be called with the project template as the current working directory. Dict's key will be the hook/script's name, without extension, while values will be the absolute path to the script. Missing scripts will not be included in the returned dict.
:param hookName: The hook to find :param hooksDir: The hook directory in the template :return: The absolute path to the hook script or null-str-list
func FindTemplate ¶
FindTemplate Determine which child directory of `repo_dir` is the project template.
:param repoDir: Local directory of newly cloned repo. :returns projectTemplate: Relative path to project template.
func GetFileName ¶
func GetFileName(replayDir, templateName string)
GetFileName Get the name of file.
func GetUserConfig ¶
GetUserConfig Return the user config as a dict.
If ``default_config`` is True, ignore ``config_file`` and return default values for the config parameters. If a path to a ``config_file`` is given, that is different from the default location, load the user config from that. Otherwise look up the config file path in the ``COOKIECUTTER_CONFIG` environment variable. If set, load the config from this path. This will raise an error if the specified path is not valid. If the environment variable is not set, try the default config file path before falling back to the default config values.
func IdentifyRepo ¶
IdentifyRepo Determine if `repo_url` should be treated as a URL to a git or hg repo.
Repos can be identified by prepending "hg+" or "git+" to the repo URL.
:param repo_url: Repo URL of unknown type. :returns: ('git', repo_url), ('hg', repo_url), or None.
func IsSlug ¶
IsSlug returns True if provided text does not contain white characters, punctuation, all letters are lower case and only from ASCII range. It could contain `-` and `_` but not at the beginning or end of the text. It should be in range of the MaxLength var if specified. All output from slug.Make(text) should pass this test.
func Make ¶
Make returns slug generated from provided string. Will use "en" as language substitution.
func MakeExecutable ¶
func MakeExecutable(scriptPath string)
MakeExecutable Make `scriptPath` executable
param scriptPath: The file to change mode
func MakeLang ¶
MakeLang returns slug generated from provided string and will use provided language for chars substitution.
func MakeSurePathExist ¶
func MergeConfigs ¶
MergeConfigs Recursively update a dict with the key/value pair of another.
Dict values that are dictionaries themselves will be updated, whilst preserving existing keys.
func ProcessJSON ¶
ProcessJSON Load user-supplied value as a JSON dict.
:param str userValue: User-supplied value to load as a JSON dict
func PromptAndDelete ¶
PromptAndDelete Ask user if it's okay to delete the previously-downloaded file/directory.
If yes, delete it. If no, checks to see if the old version should be reused. If yes, it's reused; otherwise, Cookiecutter exits.
:param path: Previously downloaded zipfile. :param noInput: Suppress prompt to delete repo and just delete it. :return: True if the content was deleted
func PromptChoiceForConfig ¶
func PromptChoiceForConfig(starterDict, env map[string]string, key string, options []string, noInput bool)
PromptChoiceForConfig Prompt user with a set of options to choose from.
Each of the possible choices is rendered beforehand.
func PromptForConfig ¶
PromptForConfig Prompt user to enter a new config.
func ReadRepoPassword ¶
ReadRepoPassword Prompt the user to enter a password.
:param str question: Question to the user
func ReadUserChoice ¶
ReadUserChoice Prompt the user to choose from several options for the given variable.
The first item will be returned if no input happens.
:param str varName: Variable as specified in the context :param list options: Sequence of options that are available to select from :return: Exactly one item of “options“ that has been chosen by the user
func ReadUserDict ¶
ReadUserDict Prompt the user to provide a dictionary of data.
:param str varName: Variable as specified in the context :param defaultValue: Value that will be returned if no input is provided :return: A Go map to use in the context.
func ReadUserVariable ¶
ReadUserVariable Prompt user for variable and return the entered value or given default.
:param str varName: Variable of the context to query the user :param defaultValue: Value that will be returned if no input happens
func ReadUserYesNo ¶
ReadUserYesNo Prompt the user to reply with 'yes' or 'no' (or equivalent values).
Note:
Possible choices are 'true', '1', 'yes', 'y' or 'false', '0', 'no', 'n'
:param str question: Question to the user :param defaultValue: Value that will be returned if no input happens
func RenderVariable ¶
RenderVariable Render the next variable to be displayed in the user prompt.
Inside the prompting taken from the cookiecutter.json file, this renders the next variable. For example, if a project_name is "Peanut Butter Cookie", the repo_name could be be rendered with:
`{{ starter.project_name.replace(" ", "_") }}`.
This is then presented to the user as the default.
:param Environment env: A Jinja2 Environment object. :param raw: The next value to be prompted for by the user. :param dict quicDict: The current context as it's gradually
being populated with variables.
:return: The rendered value for the default variable.
func RepositoryHasStarterJSON ¶
RepositoryHasStarterJSON Determine if `repoDirectory` contains a `starter.json` file.
:param repoDirectory: The candidate repository directory. :return: True if the `repo_directory` is valid, else False.
func RunHook ¶
func RunHook(hookName, projectDir string, context interface{})
RunHook Try to find and execute a hook from the specified project directory.
:param hookName: The hook to execute. :param projectdir: The directory to execute the script from. :param context: Starter project context.
func RunScript ¶
func RunScript(scriptPath, cwd string)
RunScript Execute a script from a working directory.
:param scriptPath: Absolute path to the script to run. :param cwd: The directory to run the script from.
func RunScriptWithContext ¶
func RunScriptWithContext(scriptPath, cwd string, context interface{})
RunScriptWithContext Execute a script after rendering it with Template Engine.
:param scriptPath: Absolute path to the script to run. :param cwd: The directory to run the script from. :param context: Starter project template context.
func Substitute ¶
Substitute returns string with superseded all substrings from provided substitution map. Substitution map will be applied in alphabetic order. Many passes, on one substitution another one could apply.
func SubstituteRune ¶
SubstituteRune substitutes string chars with provided rune substitution map. One pass.
func UnZipFromURL ¶
Types ¶
type ConfigDoesNotExistException ¶
type ConfigDoesNotExistException struct {
StarterException
}
ConfigDoesNotExistException Exception for missing config file.
Raised when get_config() is passed a path to a config file, but no file is found at that path.
type ContextDecodingException ¶
type ContextDecodingException struct {
StarterException
}
ContextDecodingException Exception for failed JSON decoding.
Raised when a project's JSON context file can not be decoded.
type FailedHookException ¶
type FailedHookException struct {
StarterException
}
FailedHookException Exception for hook failures.
Raised when a hook script fails.
type InvalidConfiguration ¶
type InvalidConfiguration struct {
StarterException
}
InvalidConfiguration Exception for invalid configuration file.
Raised if the global configuration file is not valid YAML or is badly constructed.
type InvalidModeException ¶
type InvalidModeException struct {
StarterException
}
InvalidModeException Exception for incompatible modes.
Raised when cookiecutter is called with both `no_input==True` and `replay==True` at the same time.
type InvalidZipRepository ¶
type InvalidZipRepository struct {
StarterException
}
InvalidZipRepository Exception for bad zip repo.
Raised when the specified cookiecutter repository isn't a valid Zip archive.
type MissingProjectDir ¶
type MissingProjectDir struct {
StarterException
}
MissingProjectDir Exception for missing generated project directory.
Raised during cleanup when remove_repo() can't find a generated project directory inside of a repo.
type NonTemplatedInputDirException ¶
type NonTemplatedInputDirException struct {
StarterException
}
NonTemplatedInputDirException Exception for when a project's input dir is not templated.
The name of the input directory should always contain a string that is rendered to something else, so that input_dir != output_dir.
type OutputDirExistsException ¶
type OutputDirExistsException struct {
StarterException
}
OutputDirExistsException Exception for existing output directory.
Raised when the output directory of the project exists already.
type RepositoryCloneFailed ¶
type RepositoryCloneFailed struct {
StarterException
}
RepositoryCloneFailed Exception for un-cloneable repo.
Raised when a cookiecutter template can't be cloned.
type RepositoryNotFound ¶
type RepositoryNotFound struct {
StarterException
}
RepositoryNotFound Exception for missing repo.
Raised when the specified cookiecutter repository doesn't exist.
type Starter ¶
type Starter struct {
}
Starter main struct&executor
func NewStarter ¶
func NewStarter(opt *StarterOption) *Starter
NewStarter create a instance of Starter
type StarterException ¶
type StarterException struct {
}
StarterException Base exception class.
All Starter-specific exceptions should subclass this class.
func (*StarterException) Error ¶
func (qe *StarterException) Error() string
type StarterOption ¶
type StarterOption struct {
Template string
Checkout string
NoInput bool
ExtraContext interface{}
Replay string
OverwriteIfExists bool
OutputDir string
ConfigFile string
UseDefaultConfig bool
Password string
Directory string
SkipIfFileExists bool
AcceptHooks bool
}
StarterOption options for create Starter
type UndefinedVariableInTemplate ¶
type UndefinedVariableInTemplate struct {
StarterException
}
UndefinedVariableInTemplate Exception for out-of-scope variables.
Raised when a template uses a variable which is not defined in the context
type UnknownExtension ¶
type UnknownExtension struct {
StarterException
}
UnknownExtension Exception for un-importable extention.
Raised when an environment is unable to import a required extension.
type UnknownRepoType ¶
type UnknownRepoType struct {
StarterException
}
UnknownRepoType Exception for unknown repo types
Raised if a repo's type cannot be determined.
func (*UnknownRepoType) Error ¶
func (ur *UnknownRepoType) Error() string
type UnknownTemplateDirException ¶
type UnknownTemplateDirException struct {
StarterException
}
type VCSNotInstalled ¶
type VCSNotInstalled struct {
StarterException
}
VCSNotInstalled Exception when version control is unavailable.
Raised if the version control system (git or hg) is not installed.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
* @Description: 填写描述 * @Author: WangXinyong/TaceyWong * @Date: 2020-09-25 10:27:14 * @LastEditors: WangXinyong/TaceyWong * @LastEditTime: 2020-09-25 13:14:46 * @FilePath: /quick/cmd/cli.go
|
* @Description: 填写描述 * @Author: WangXinyong/TaceyWong * @Date: 2020-09-25 10:27:14 * @LastEditors: WangXinyong/TaceyWong * @LastEditTime: 2020-09-25 13:14:46 * @FilePath: /quick/cmd/cli.go |