@@ -2,7 +2,6 @@ package config
22
33import (
44 "os"
5- "os/user"
65 "path/filepath"
76 "strings"
87
@@ -11,7 +10,6 @@ import (
1110
1211 "github.com/go-flutter-desktop/hover/internal/build"
1312 "github.com/go-flutter-desktop/hover/internal/log"
14- "github.com/go-flutter-desktop/hover/internal/pubspec"
1513)
1614
1715// BuildTargetDefault Default build target file
@@ -29,62 +27,44 @@ const BuildOpenGlVersionDefault = "3.3"
2927// Config contains the parsed contents of hover.yaml
3028type Config struct {
3129 loaded bool
32- applicationName string `yaml:"application-name"`
33- executableName string `yaml:"executable-name"`
34- packageName string `yaml:"package-name"`
35- license string
30+ ApplicationName string `yaml:"application-name"`
31+ ExecutableName string `yaml:"executable-name"`
32+ PackageName string `yaml:"package-name"`
33+ License string
3634 Target string
3735 Branch string
3836 CachePath string `yaml:"cache-path"`
3937 OpenGL string
4038 Engine string `yaml:"engine-version"`
4139}
4240
43- func (c Config ) ApplicationName (projectName string ) string {
44- if c .applicationName == "" {
41+ func (c Config ) GetApplicationName (projectName string ) string {
42+ if c .ApplicationName == "" {
4543 return projectName
4644 }
47- return c .applicationName
45+ return c .ApplicationName
4846}
4947
50- func (c Config ) ExecutableName (projectName string ) string {
51- if c .executableName == "" {
48+ func (c Config ) GetExecutableName (projectName string ) string {
49+ if c .ExecutableName == "" {
5250 return strings .ReplaceAll (projectName , " " , "" )
5351 }
54- return c .executableName
52+ return c .ExecutableName
5553}
5654
57- func (c Config ) PackageName (projectName string ) string {
58- if c .packageName == "" {
55+ func (c Config ) GetPackageName (projectName string ) string {
56+ if c .PackageName == "" {
5957 return strings .ReplaceAll (strings .ReplaceAll (strings .ReplaceAll (projectName , "-" , "" ), "_" , "" ), " " , "" )
6058 }
61- return c .packageName
59+ return c .PackageName
6260}
6361
64- func (c Config ) License () string {
65- if c .license == "" {
66- log .Warnf ("Missing/Empty `license` field in go/hover.yaml." )
67- log .Warnf ("Please add it otherwise you may publish your app with a wrong license." )
68- log .Warnf ("Continuing with `NOASSERTION` as a placeholder license." )
69- return "NOASSERTION"
62+ func (c Config ) GetLicense () string {
63+ if len (c .License ) == 0 {
64+ c .License = "NOASSERTION"
65+ PrintMissingField ("license" , "go/hover.yaml" , c .License )
7066 }
71- return c .license
72- }
73-
74- func (c Config ) Author () string {
75- author := pubspec .GetPubSpec ().Author
76- if author == "" {
77- log .Warnf ("Missing author field in pubspec.yaml" )
78- log .Warnf ("Please add the `author` field to your pubspec.yaml" )
79- u , err := user .Current ()
80- if err != nil {
81- log .Errorf ("Couldn't get current user: %v" , err )
82- os .Exit (1 )
83- }
84- author = u .Username
85- log .Printf ("Using this username from system instead: %s" , author )
86- }
87- return author
67+ return c .License
8868}
8969
9070var config = Config {}
@@ -121,3 +101,7 @@ func ReadConfigFile(configPath string) (*Config, error) {
121101 }
122102 return & config , nil
123103}
104+
105+ func PrintMissingField (name , file , def string ) {
106+ log .Warnf ("Missing/Empty `%s` field in %s. Please add it or otherwise you may publish your app with a wrong %s. Continuing with `%s` as a placeholder %s." , name , file , name , def , name )
107+ }
0 commit comments