-
-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: jsonschema Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * fix: gitattr Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * docs: schema Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * docs: schema Signed-off-by: Carlos A Becker <caarlos0@gmail.com> * docs: improvements Signed-off-by: Carlos A Becker <caarlos0@gmail.com>
- Loading branch information
Showing
11 changed files
with
769 additions
and
66 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
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
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
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
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,53 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"os" | ||
"path/filepath" | ||
|
||
"github.com/alecthomas/jsonschema" | ||
"github.com/goreleaser/nfpm/v2" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
type schemaCmd struct { | ||
cmd *cobra.Command | ||
output string | ||
} | ||
|
||
func newSchemaCmd() *schemaCmd { | ||
root := &schemaCmd{} | ||
cmd := &cobra.Command{ | ||
Use: "jsonschema", | ||
Aliases: []string{"schema"}, | ||
Short: "outputs nFPM's JSON schema", | ||
SilenceUsage: true, | ||
SilenceErrors: true, | ||
Args: cobra.NoArgs, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
schema := jsonschema.Reflect(&nfpm.Config{}) | ||
schema.Description = "nFPM configuration definition file" | ||
bts, err := json.MarshalIndent(schema, " ", " ") | ||
if err != nil { | ||
return fmt.Errorf("failed to create jsonschema: %w", err) | ||
} | ||
if root.output == "-" { | ||
fmt.Println(string(bts)) | ||
return nil | ||
} | ||
if err := os.MkdirAll(filepath.Dir(root.output), 0o755); err != nil { | ||
return fmt.Errorf("failed to write jsonschema file: %w", err) | ||
} | ||
if err := os.WriteFile(root.output, bts, 0o666); err != nil { | ||
return fmt.Errorf("failed to write jsonschema file: %w", err) | ||
} | ||
return nil | ||
}, | ||
} | ||
|
||
cmd.Flags().StringVarP(&root.output, "output", "o", "-", "where to save the json schema") | ||
|
||
root.cmd = cmd | ||
return root | ||
} |
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
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
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
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 |
---|---|---|
@@ -1,6 +1,6 @@ | ||
# nfpm jsonschema | ||
|
||
creates a JSON schema file | ||
outputs nFPM's JSON schema | ||
|
||
``` | ||
nfpm jsonschema [flags] | ||
|
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
Oops, something went wrong.
5c895f6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs: