Documentation
¶
Overview ¶
Package site resolves the website a command acts on and remembers it per directory, like `vercel link`.
Index ¶
- Constants
- Variables
- func CommittedLink(dir string) string
- func DefaultDomain(cmd *cobra.Command) (string, error)
- func HostingPlanNames(ctx context.Context, c *api.RawClient) (map[int]string, error)
- func Label(w Website) string
- func LinkDirs(start string) ([]string, error)
- func NormalizeDomain(s string) string
- func Path(dir string) string
- func PlanLabels(sites []Website, names map[int]string) map[int]string
- func PlanNames(orders []HostingOrder) map[int]string
- func PlanOption(w Website, labels map[int]string) string
- func PlanOptions(orders []HostingOrder) []string
- func Portfolio(ctx context.Context) ([]string, error)
- func Remove(dir string) error
- func Resolve(cmd *cobra.Command, args []string, extras int) (username, domain string, rest []string, err error)
- func ResolveBuild(cmd *cobra.Command, args []string, extras int) (username, domain, build string, rest []string, err error)
- func ResolveDomain(cmd *cobra.Command, args []string, extras int, group string) (domain string, rest []string, err error)
- func ResolveOrder(cmd *cobra.Command, args []string, extras int, group string) (orderID string, rest []string, err error)
- func ResolveUsername(cmd *cobra.Command, args []string, extras int) (username string, rest []string, err error)
- func Save(dir string, p *Project) error
- func SelectHeight(options int) int
- func SortByPlan(sites []Website, labels map[int]string)
- func Username(ctx context.Context, domain string) (string, error)
- type BuildRef
- type Context
- type HostingOrder
- type NodeSettings
- type Order
- type Project
- type Website
- func ChooseWebsite(ctx context.Context, current string) (*Website, error)
- func FindWebsite(ctx context.Context, c *api.RawClient, domain string) (*Website, error)
- func FindWebsiteWith(ctx context.Context, list func(context.Context, string) ([]Website, error), ...) (*Website, error)
- func ListWebsites(ctx context.Context, domain string) ([]Website, error)
- func ListWebsitesWith(ctx context.Context, c *api.RawClient, domain string) ([]Website, error)
Constants ¶
const ( Dir = ".hostinger" // File is shared with the deploy-to-hosting skill, so Save keeps its fields. File = "site.json" )
Variables ¶
var Client = func() *api.RawClient { return api.Raw() }
Tests replace Client.
var ErrNoBuild error = &utils.FlagError{Err: errors.New("no build given: pass the build UUID")}
var ErrNoDomain error = &utils.FlagError{Err: errors.New("no domain given: pass the domain or --domain")}
var ErrNoOrder error = &utils.FlagError{Err: errors.New("no order given: pass the order ID")}
var ErrNoUsername error = &utils.FlagError{Err: errors.New("no hosting account given: pass the username, or run `hostinger link`")}
var ErrNoWebsite error = &utils.FlagError{Err: errors.New("no website given: pass the domain, or run `hostinger link`")}
var Interactive = func() bool { if viper.GetBool("no_input") || os.Getenv("HOSTINGER_MAIL_NONINTERACTIVE") != "" { return false } if ci := strings.ToLower(os.Getenv("CI")); ci != "" && ci != "false" && ci != "0" { return false } return term.IsTerminal(int(os.Stdin.Fd())) && term.IsTerminal(int(os.Stderr.Fd())) }
Interactive also checks CI and HOSTINGER_MAIL_NONINTERACTIVE: agents and CI runners often have a pseudo-terminal. Tests replace it.
var Spin = func(msg string) func(done string) { if !Interactive() { return func(string) {} } sp, err := pterm.DefaultSpinner.WithWriter(os.Stderr).Start(msg) if err != nil { return func(string) {} } return func(done string) { sp.Success(done) } }
Spin shows a spinner on stderr in a terminal; call the result to end it. Tests replace it.
Functions ¶
func CommittedLink ¶ added in v1.7.1
CommittedLink returns the link file in dir that Load reads when Git tracks it, else "". A cloned repository can ship one naming someone else's website, so a committed link is not consent to replace it. A repository that cannot be read counts as tracking it.
func DefaultDomain ¶
DefaultDomain is the website named by flags, env, link or config, not args. A link that cannot be read is an error only when it is consulted.
func HostingPlanNames ¶
func LinkDirs ¶
LinkDirs are where a link for start can live: start, then its parents up to the repository root. It never climbs into the home directory or above, so a link made there once does not apply to every project below it.
func NormalizeDomain ¶
NormalizeDomain turns a pasted URL into a domain (no scheme, path, port, trailing dot or www.).
func PlanLabels ¶
PlanLabels are a grouped picker's labels: unknown orders read "Order N", same-named plans get their order id, and one plan gives nil (a flat picker).
func PlanNames ¶
func PlanNames(orders []HostingOrder) map[int]string
func PlanOptions ¶ added in v1.8.5
func PlanOptions(orders []HostingOrder) []string
PlanOptions add the order id only to tell same-named plans apart.
func Remove ¶ added in v1.7.1
Remove deletes the link files only: Dir can also hold other tools' files (the headless skill's workspaces under ~/.hostinger). Dir goes too once empty, unless it is a symlinked, shared folder.
func Resolve ¶
func Resolve(cmd *cobra.Command, args []string, extras int) (username, domain string, rest []string, err error)
Resolve returns a site-scoped command's website and the remaining args. One arg is the domain; none means --domain, HOSTINGER_MAIL_DOMAIN, the link, default_domain, then a prompt.
func ResolveBuild ¶
func ResolveBuild(cmd *cobra.Command, args []string, extras int) (username, domain, build string, rest []string, err error)
ResolveBuild is Resolve plus [build-uuid]: a UUID-shaped arg is the build; else the build up last started, else a prompt.
func ResolveDomain ¶
func ResolveDomain(cmd *cobra.Command, args []string, extras int, group string) (domain string, rest []string, err error)
ResolveDomain: for hosting the domain is a website (see Resolve). For domains and DNS the link only counts when its domain is in the portfolio, since a free subdomain is not a zone.
func ResolveOrder ¶
func ResolveOrder(cmd *cobra.Command, args []string, extras int, group string) (orderID string, rest []string, err error)
ResolveOrder: arg, else --order-id, HOSTINGER_MAIL_ORDER_ID, the link (hosting only), then a prompt.
func ResolveUsername ¶
func ResolveUsername(cmd *cobra.Command, args []string, extras int) (username string, rest []string, err error)
ResolveUsername: arg, else --username, HOSTINGER_MAIL_USERNAME, the account of the default website, then a prompt.
func Save ¶
Save writes the link, keeping other tools' fields, and gitignores Dir since it names the hosting account.
func SelectHeight ¶
SelectHeight fits the list below the question, at least five rows.
func SortByPlan ¶
Types ¶
type Context ¶ added in v1.5.0
type Context struct {
Domain string `json:"domain,omitempty"`
DomainSource string `json:"domainSource"`
Username string `json:"username,omitempty"`
UsernameSource string `json:"usernameSource,omitempty"`
OrderID string `json:"orderId,omitempty"`
OrderSource string `json:"orderSource,omitempty"`
LinkFile string `json:"linkFile,omitempty"`
Link *Project `json:"link,omitempty"`
ConfigFile string `json:"configFile,omitempty"`
}
Context is what `hostinger link --show` prints: each value and its source.
type HostingOrder ¶
type HostingOrder struct {
ID int `json:"id"`
Status string `json:"status"`
SubscriptionID string `json:"subscription_id"`
Plan struct {
Name string `json:"name"`
} `json:"plan"`
// DisplayName comes from the billing subscription, when known.
DisplayName string `json:"-"`
}
func HostingOrders ¶
HostingOrders names each order after its billing subscription, since the orders API only has the plan key.
func (HostingOrder) Label ¶
func (o HostingOrder) Label() string
Label leaves out the order id, which means nothing to most people.
type NodeSettings ¶
type NodeSettings struct {
NodeVersion int `json:"nodeVersion,omitempty"`
AppType string `json:"appType,omitempty"`
RootDirectory string `json:"rootDirectory,omitempty"`
OutputDirectory string `json:"outputDirectory,omitempty"`
BuildScript string `json:"buildScript,omitempty"`
EntryFile string `json:"entryFile,omitempty"`
PackageManager string `json:"packageManager,omitempty"`
}
NodeSettings are remembered build settings; empty strings mean "not set".
type Order ¶
Order is any product's order, reduced to what a prompt needs.
func ChooseOrder ¶
ChooseOrder returns the only usable order without asking.
type Project ¶
type Project struct {
// Kind is "website"; empty in older files means the same.
Kind string `json:"kind,omitempty"`
// Path is the deployed folder relative to the link; empty is the directory itself.
Path string `json:"path,omitempty"`
OrderID int `json:"orderId,omitempty"`
Domain string `json:"domain"`
Username string `json:"username,omitempty"`
Type string `json:"type,omitempty"`
// Headless is set for a headless website, which only takes Node.js deploys.
Headless bool `json:"headless,omitempty"`
// Source is "upload" or "git".
Source string `json:"source,omitempty"`
// Node is only written after a successful build.
Node *NodeSettings `json:"node,omitempty"`
// Build is the last build up started, so the build commands default to it.
Build *BuildRef `json:"build,omitempty"`
}
type Website ¶
type Website struct {
Domain string `json:"domain"`
Username string `json:"username"`
OrderID int `json:"order_id"`
WebsiteType string `json:"website_type"`
VhostType string `json:"vhost_type"`
IsEnabled bool `json:"is_enabled"`
}
func ChooseWebsite ¶
ChooseWebsite returns the only website without asking; current is preselected.
func FindWebsite ¶
func FindWebsiteWith ¶
func ListWebsites ¶
ListWebsites filters by domain as a substring; empty lists all.
func ListWebsitesWith ¶
func (Website) IsHeadless ¶ added in v1.7.0
IsHeadless reports a headless website: a Node.js frontend whose backend (WordPress, a store, PocketBase) lives in its own folder, such as /cms.