Skip to content

Commit 9572c81

Browse files
authored
Merge pull request #22 from 1ed/create-php-version-file
Add .php-version for new projects created with --php
2 parents 0ac6b74 + 328136f commit 9572c81

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

commands/local_new.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,12 @@ var localNewCmd = &console.Command{
146146
return err
147147
}
148148

149+
if "" != c.String("php") && !c.Bool("cloud") {
150+
if err := createPhpVersionFile(c.String("php"), dir); err != nil {
151+
return err
152+
}
153+
}
154+
149155
if !c.Bool("no-git") {
150156
if _, err := exec.LookPath("git"); err == nil {
151157
if err := initProjectGit(c, s, dir); err != nil {
@@ -371,3 +377,19 @@ func forcePHPVersion(v, dir string) (string, error) {
371377
os.Setenv("FORCED_PHP_VERSION", v)
372378
return strings.Join(strings.Split(v, ".")[0:2], "."), nil
373379
}
380+
381+
func createPhpVersionFile(v, dir string) error {
382+
file := filepath.Join(dir, ".php-version")
383+
f, err := os.OpenFile(file, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0644)
384+
if err != nil {
385+
return errors.Wrapf(err, "unable to create %s", file)
386+
}
387+
if _, err = f.WriteString(v + "\n"); err != nil {
388+
f.Close()
389+
return errors.Wrapf(err, "unable to write %s", file)
390+
}
391+
if err = f.Close(); err != nil {
392+
return errors.Wrapf(err, "unable to close %s", file)
393+
}
394+
return nil
395+
}

0 commit comments

Comments
 (0)