@@ -2,6 +2,8 @@ package common
22
33import (
44 "fmt"
5+ "regexp"
6+ "strings"
57
68 "github.com/spf13/cobra"
79
@@ -10,6 +12,14 @@ import (
1012 cliConfig "github.com/oasisprotocol/cli/config"
1113)
1214
15+ var (
16+ // orcFilenameDisallowedChars is a regexp matching characters that are not allowed in filenames.
17+ orcFilenameDisallowedChars = regexp .MustCompile ("[^a-zA-Z0-9-]" )
18+
19+ // orcFilenameRepeatedChars is a regexp matching repeats of dash characters in filenames.
20+ orcFilenameRepeatedChars = regexp .MustCompile ("(-){2,}" )
21+ )
22+
1323// ManifestOptions configures the manifest options.
1424type ManifestOptions struct {
1525 // NeedAppID specifies whether a configured app ID is required in the manifest.
@@ -98,5 +108,9 @@ func MaybeLoadManifestAndSetNPA(cfg *cliConfig.Config, npa *common.NPASelection,
98108
99109// GetOrcFilename generates a filename based on the project name and deployment.
100110func GetOrcFilename (manifest * rofl.Manifest , deploymentName string ) string {
101- return fmt .Sprintf ("%s.%s.orc" , manifest .Name , deploymentName )
111+ normalizedName := strings .ToLower (manifest .Name )
112+ normalizedName = strings .TrimSpace (normalizedName )
113+ normalizedName = orcFilenameDisallowedChars .ReplaceAllString (normalizedName , "-" )
114+ normalizedName = orcFilenameRepeatedChars .ReplaceAllString (normalizedName , "$1" )
115+ return fmt .Sprintf ("%s.%s.orc" , normalizedName , deploymentName )
102116}
0 commit comments