@@ -16,22 +16,40 @@ type githubConf struct {
1616 FragmentListingEnv string // name of env var containing a list of file fragments
1717}
1818
19- func parseArgs (args []string ) (* changelog.Config , * githubConf , error ) {
19+ func parseArgs (args []string ) (c * changelog.Config , envConf * githubConf , err error ) {
2020 flags := flag .NewFlagSet ("check" , flag .ContinueOnError )
21- c := & changelog.Config {RepoConfig : changelog.RepoConfig {Owner : "prysmaticlabs" , Repo : "prysm" }, ReleaseTime : time .Now ()}
21+ flags .Usage = func () {
22+ fmt .Fprintf (flag .CommandLine .Output (), "Usage of %s:\n " , os .Args [0 ])
23+ flags .PrintDefaults ()
24+ fmt .Fprint (flag .CommandLine .Output (), "\n " )
25+ }
26+ defer func () {
27+ if err != nil {
28+ flags .Usage ()
29+ }
30+ }()
31+
32+ c = & changelog.Config {RepoConfig : changelog.RepoConfig {Owner : "prysmaticlabs" , Repo : "prysm" }, ReleaseTime : time .Now ()}
2233 flags .StringVar (& c .RepoPath , "repo" , "" , "Path to the git repository" )
2334 flags .StringVar (& c .ChangesDir , "changelog-dir" , "changelog" , "Path to the directory containing changelog fragments for each commit" )
2435 flags .StringVar (& c .RepoConfig .MainRev , "main-rev" , "origin/develop" , "Main branch tip revision" )
2536 flags .StringVar (& c .Branch , "branch" , "HEAD" , "branch tip revision" )
2637 envCfg := & githubConf {}
2738 flags .StringVar (& envCfg .FragmentListingEnv , "fragment-env" , "" , "Name of the environment variable containing a list of changelog fragments" )
2839 flags .Parse (args )
40+ if c .RepoPath == "" {
41+ wd , err := os .Getwd ()
42+ if err != nil {
43+ return nil , envCfg , fmt .Errorf ("repo flag not set and can't get working directory from syscall, %w" , err )
44+ }
45+ c .RepoPath = wd
46+ }
2947 if envCfg .FragmentListingEnv != "" {
3048 return nil , envCfg , nil
3149 }
3250
3351 if c .RepoPath == "" {
34- return c , nil , fmt .Errorf ("repo is required" )
52+ return c , nil , fmt .Errorf ("- repo flag is required" )
3553 }
3654 return c , nil , nil
3755}
@@ -75,6 +93,9 @@ func checkFragments(envCfg *githubConf) error {
7593 }
7694 lines := strings .Split (string (b ), "\n " )
7795 parsed := changelog .ParseFragment (lines , "" )
96+ if len (parsed ) == 0 {
97+ return fmt .Errorf ("please check formatting of fragment file at %s, could not find any bullet points within valid sections" , p )
98+ }
7899 for k , v := range parsed {
79100 if len (v ) == 0 {
80101 delete (parsed , k )
0 commit comments