@@ -685,16 +685,55 @@ func editWikiPage(title string) error {
685
685
return nil
686
686
}
687
687
688
- func initConfigFile () error {
688
+ func initConfigFile (endpoint string , apikey string , project string ) error {
689
689
template := `{
690
- "endpoint": "http://redmine.example.com ",
691
- "apikey": "YOUR-API-KEY ",
692
- "project": 1 // default project id
690
+ "endpoint": "%s ",
691
+ "apikey": "%s ",
692
+ "project": %s
693
693
}`
694
+ content := fmt .Sprintf (template , endpoint , apikey , project );
694
695
695
696
file := createConfigFileName ()
697
+ dir := filepath .Dir (file )
696
698
697
- return ioutil .WriteFile (file , []byte (template ), 0600 )
699
+ if _ , err := os .Stat (dir ); err != nil {
700
+ os .MkdirAll (dir , 0755 )
701
+ }
702
+
703
+ return ioutil .WriteFile (file , []byte (content ), 0600 )
704
+ }
705
+
706
+ func listConfigFile () error {
707
+ file := createConfigFileName ()
708
+ dir := filepath .Dir (file )
709
+
710
+ files , err := ioutil .ReadDir (dir )
711
+ if err != nil {
712
+ fmt .Println ("Directory not exists: %s" , dir )
713
+ return err
714
+ }
715
+
716
+ for _ , file := range files {
717
+ fmt .Println (file .Name ())
718
+ }
719
+
720
+ return nil
721
+ }
722
+
723
+ func showConfigFile () error {
724
+ file := createConfigFileName ()
725
+
726
+ fmt .Println (file )
727
+
728
+ content , err := ioutil .ReadFile (file )
729
+ if err != nil {
730
+ fmt .Println ("File not exists: %s" , file )
731
+ return err
732
+ }
733
+
734
+ fmt .Println (string (content ))
735
+
736
+ return nil
698
737
}
699
738
700
739
func editConfigFile () error {
@@ -828,7 +867,13 @@ func main() {
828
867
editConfigFile ()
829
868
break
830
869
case "i" , "init" :
831
- initConfigFile ()
870
+ initConfigFile (flag .Arg (2 ), flag .Arg (3 ), flag .Arg (4 ))
871
+ break
872
+ case "l" , "list" :
873
+ listConfigFile ()
874
+ break
875
+ case "s" , "show" :
876
+ showConfigFile ()
832
877
break
833
878
default :
834
879
usage ()
0 commit comments