Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MUTAGEN_PROJECT_FILE env variable #203

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/mutagen/project/flush.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func flushMain(command *cobra.Command, arguments []string) error {
// relative paths (including relative synchronization paths and relative
// Unix Domain Socket paths) to be resolved relative to the project
// configuration file.
configurationFileName := project.DefaultConfigurationFileName
configurationFileName := project.ConfigurationFileName()
if flushConfiguration.projectFile != "" {
var directory string
directory, configurationFileName = filepath.Split(flushConfiguration.projectFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mutagen/project/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func listMain(command *cobra.Command, arguments []string) error {
// relative paths (including relative synchronization paths and relative
// Unix Domain Socket paths) to be resolved relative to the project
// configuration file.
configurationFileName := project.DefaultConfigurationFileName
configurationFileName := project.ConfigurationFileName()
if listConfiguration.projectFile != "" {
var directory string
directory, configurationFileName = filepath.Split(listConfiguration.projectFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mutagen/project/pause.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func pauseMain(command *cobra.Command, arguments []string) error {
// relative paths (including relative synchronization paths and relative
// Unix Domain Socket paths) to be resolved relative to the project
// configuration file.
configurationFileName := project.DefaultConfigurationFileName
configurationFileName := project.ConfigurationFileName()
if pauseConfiguration.projectFile != "" {
var directory string
directory, configurationFileName = filepath.Split(pauseConfiguration.projectFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mutagen/project/reset.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func resetMain(command *cobra.Command, arguments []string) error {
// relative paths (including relative synchronization paths and relative
// Unix Domain Socket paths) to be resolved relative to the project
// configuration file.
configurationFileName := project.DefaultConfigurationFileName
configurationFileName := project.ConfigurationFileName()
if resetConfiguration.projectFile != "" {
var directory string
directory, configurationFileName = filepath.Split(resetConfiguration.projectFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mutagen/project/resume.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func resumeMain(command *cobra.Command, arguments []string) error {
// relative paths (including relative synchronization paths and relative
// Unix Domain Socket paths) to be resolved relative to the project
// configuration file.
configurationFileName := project.DefaultConfigurationFileName
configurationFileName := project.ConfigurationFileName();
if resumeConfiguration.projectFile != "" {
var directory string
directory, configurationFileName = filepath.Split(resumeConfiguration.projectFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mutagen/project/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func runMain(_ *cobra.Command, arguments []string) error {
// relative paths (including relative synchronization paths and relative
// Unix Domain Socket paths) to be resolved relative to the project
// configuration file.
configurationFileName := project.DefaultConfigurationFileName
configurationFileName := project.ConfigurationFileName()
if runConfiguration.projectFile != "" {
var directory string
directory, configurationFileName = filepath.Split(runConfiguration.projectFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mutagen/project/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func startMain(command *cobra.Command, arguments []string) error {
// relative paths (including relative synchronization paths and relative
// Unix Domain Socket paths) to be resolved relative to the project
// configuration file.
configurationFileName := project.DefaultConfigurationFileName
configurationFileName := project.ConfigurationFileName()
Copy link
Member

@xenoscopic xenoscopic May 21, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the MUTAGEN_PROJECT_FILE environment variable allows a path to be specified (as opposed to just a filename), then I think the same os.Chdir logic used for a project file specified on the command line will be needed to support relative synchronization paths. This applies at least in the start command, but I think in the other commands as well.

if startConfiguration.projectFile != "" {
var directory string
directory, configurationFileName = filepath.Split(startConfiguration.projectFile)
Expand Down
2 changes: 1 addition & 1 deletion cmd/mutagen/project/terminate.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func terminateMain(command *cobra.Command, arguments []string) error {
// relative paths (including relative synchronization paths and relative
// Unix Domain Socket paths) to be resolved relative to the project
// configuration file.
configurationFileName := project.DefaultConfigurationFileName
configurationFileName := project.ConfigurationFileName()
if terminateConfiguration.projectFile != "" {
var directory string
directory, configurationFileName = filepath.Split(terminateConfiguration.projectFile)
Expand Down
10 changes: 10 additions & 0 deletions pkg/project/paths.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package project

import "os"

const (
// DefaultConfigurationFileName is the name of the Mutagen project
// configuration file.
Expand All @@ -8,3 +10,11 @@ const (
// order to compute the corresponding lock file.
LockFileExtension = ".lock"
)

func ConfigurationFileName() string {
fileName := os.Getenv("MUTAGEN_PROJECT_FILE")
if fileName == "" {
return DefaultConfigurationFileName
}
return fileName
}
Comment on lines +14 to +20
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks like it needs to be go fmt'd since it's using spaces for indentation. You can format all of your changes with

go fmt ./cmd/mutagen/project/...
go fmt ./pkg/project/...

(assuming you're in the root of the source directory).

This is one of those weird Go things, but basically Go's canonical style is "whatever the gofmt tool decides." For indentation, Go prefers tabs (though it does use spaces for alignment).