-
Notifications
You must be signed in to change notification settings - Fork 114
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
introduce compose-spec command line for compose file validation
Signed-off-by: Nicolas De Loof <[email protected]>
- Loading branch information
Showing
1 changed file
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
Copyright 2020 The Compose Specification Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package main | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/compose-spec/compose-go/v2/cli" | ||
) | ||
|
||
func main() { | ||
if len(os.Args) == 1 { | ||
fmt.Println(` | ||
Check failure on line 28 in cmd/main.go GitHub Actions / test (1.20, macos-latest)
|
||
Validates a compose file conforms to the Compose Specification | ||
Usage: compose-spec [OPTIONS] COMPOSE_FILE [COMPOSE_OVERRIDE_FILE] | ||
`) | ||
} | ||
|
||
wd, err := os.Getwd() | ||
if err != nil { | ||
fmt.Errorf("can't determine current directory: %w", err) | ||
Check failure on line 37 in cmd/main.go GitHub Actions / test (1.20, macos-latest)
|
||
os.Exit(1) | ||
} | ||
|
||
options, err := cli.NewProjectOptions(os.Args[1:], | ||
cli.WithWorkingDirectory(wd), | ||
cli.WithOsEnv, | ||
cli.WithDotEnv, | ||
cli.WithConfigFileEnv, | ||
cli.WithDefaultConfigPath, | ||
) | ||
if err != nil { | ||
fmt.Errorf("failed to configure project options: %w", err) | ||
Check failure on line 49 in cmd/main.go GitHub Actions / test (1.20, macos-latest)
|
||
os.Exit(1) | ||
} | ||
|
||
project, err := cli.ProjectFromOptions(options) | ||
if err != nil { | ||
fmt.Errorf("failed to load project: %w", err) | ||
Check failure on line 55 in cmd/main.go GitHub Actions / test (1.20, macos-latest)
|
||
os.Exit(1) | ||
} | ||
|
||
yaml, err := project.MarshalYAML() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "failed to marshall project: %w", err) | ||
Check failure on line 61 in cmd/main.go GitHub Actions / test (1.20, macos-latest)
|
||
os.Exit(1) | ||
} | ||
fmt.Println(string(yaml)) | ||
} |