Skip to content
This repository has been archived by the owner on Jul 11, 2022. It is now read-only.

Commit

Permalink
Merge branch 'release/0.11.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccallister committed Apr 29, 2020
2 parents d57b432 + 1537185 commit 20fd660
Show file tree
Hide file tree
Showing 37 changed files with 1,583 additions and 469 deletions.
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,27 @@

## Unreleased

## 0.11.0 - 2020-04-29

## Added
- Added the `rename` command to allow users to quickly rename sites.

## Changed
- The `destroy` command now has a `--clean` option which will delete a config file after destroying the machine.
- The `nitro` database user now has root privileges for `mysql` and `postgres` databases. [#79](https://github.com/craftcms/nitro/issues/79)
- Added the `php` option back to the config file.
- All commands that perform config changes (e.g. `add`, `remove`, and `rename`) now use the same logic as the `apply` command.
- When importing a database using the `import` command, users will be prompted for the database name which will be created if it does not exist.
- The `apply` command will automatically update the machine's hosts file.
- The `destroy` command will now remove any sites in the machine config from the hosts file.
- The `init` command will use an existing config file and recreate the entire environment.
- Commands now output more _statuses_ where possible to provide the user more feedback.

## Fixed
- When using the `add` command, the config file checks for duplicate sites and mounts. [#86](https://github.com/craftcms/nitro/issues/86)
- Fixed an issue when using some commands on Windows. [#88](https://github.com/craftcms/nitro/issues/88)
- Fixed an issue in the `apply` command that would not detect new changes to the config file.

## 0.10.0 - 2020-04-23

> **Warning:** This release contains breaking changes. See the [upgrade notes](UPGRADE.md#upgrading-to-nitro-0100)
Expand Down
95 changes: 73 additions & 22 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import (
)

type Config struct {
PHP string `yaml:"-"`
PHP string `yaml:"php"`
CPUs string `yaml:"-"`
Disk string `yaml:"-"`
Memory string `yaml:"-"`
Expand All @@ -23,39 +23,60 @@ type Config struct {
Sites []Site `yaml:"sites,omitempty"`
}

type Mount struct {
Source string `yaml:"source"`
Dest string `yaml:"dest"`
func (c *Config) AddSite(site Site) error {
if len(site.Aliases) == 0 {
site.Aliases = nil
}

c.Sites = append(c.Sites, site)
return nil
}

type Database struct {
Engine string `yaml:"engine"`
Version string `yaml:"version"`
Port string `yaml:"port"`
func (c *Config) GetSites() []Site {
return c.Sites
}

type Site struct {
Hostname string `yaml:"hostname"`
Webroot string `yaml:"webroot"`
Aliases []string `yaml:"aliases,omitempty"`
// GetExpandedMounts will take all of the mounts in a config file
// and "expand" or get the full path mount source and return
// a slice of mounts
func (c *Config) GetExpandedMounts() []Mount {
var mounts []Mount
for _, m := range c.Mounts {
mounts = append(mounts, Mount{Source: m.AbsSourcePath(), Dest: m.Dest})
}
return mounts
}

func (m *Mount) AbsSourcePath() string {
home, _ := homedir.Dir()
return strings.Replace(m.Source, "~", home, 1)
// MountExists will check if a mount exists by checking if it is an exact
// dest or a parent of an existing dest
func (c *Config) MountExists(dest string) bool {
for _, mount := range c.Mounts {
if mount.IsExact(dest) || mount.IsParent(dest) {
return true
}
}

return false
}

func (c *Config) AddSite(site Site) error {
if len(site.Aliases) == 0 {
site.Aliases = nil
func (c *Config) SiteExists(site Site) bool {
for _, s := range c.Sites {
if s.IsExact(site) {
return true
}
}

c.Sites = append(c.Sites, site)
return nil
return false
}

func (c *Config) GetSites() []Site {
return c.Sites
func (c *Config) DatabaseExists(database Database) bool {
for _, d := range c.Databases {
if d.Engine == database.Engine && d.Version == database.Version && d.Port == database.Port {
return true
}
}

return false
}

func (c *Config) SitesAsList() []string {
Expand Down Expand Up @@ -106,6 +127,36 @@ func (c *Config) AddMount(m Mount) error {
return nil
}

func (c *Config) RenameSite(site Site, hostname string) error {
for i, s := range c.Sites {
if s.Hostname == site.Hostname {
w := strings.Replace(s.Webroot, s.Hostname, hostname, 1)
c.Sites[i] = Site{Hostname: hostname, Webroot: w}

return nil
}
}

return errors.New("unable to locate the site with the hostname: " + site.Hostname)
}

func (c *Config) RenameMountBySite(site Site) error {
for i, mount := range c.Mounts {
sp := strings.Split(site.Webroot, "/")
siteMount := sp[len(sp)-1]
if strings.Contains(mount.Dest, siteMount) {
c.Mounts[i] = Mount{
Source: mount.Source,
Dest: siteMount,
}

return nil
}
}

return errors.New("unable to find the mount for the site " + site.Hostname)
}

func (c *Config) RemoveSite(hostname string) error {
for i := len(c.Sites) - 1; i >= 0; i-- {
site := c.Sites[i]
Expand Down
Loading

0 comments on commit 20fd660

Please sign in to comment.