Skip to content

Commit

Permalink
Add stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
jafarlihi committed Nov 19, 2022
1 parent 2fca7f5 commit 48fbdc1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
4 changes: 2 additions & 2 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func LoadConfig() {
if _, err := os.Stat(homePath + "/.config/rssnix/config.ini"); errors.Is(err, os.ErrNotExist) {
log.Warn("Config file does not exist, creating...")

os.MkdirAll(homePath+"/.config/rssnix", 0744)
os.MkdirAll(homePath+"/.config/rssnix", 0644)
file, err := os.Create(homePath + "/.config/rssnix/config.ini")
if err != nil {
log.Error("Failed to create a config file")
Expand All @@ -57,7 +57,7 @@ func LoadConfig() {
if strings.HasPrefix(Config.FeedDirectory, "~") {
Config.FeedDirectory = homePath + Config.FeedDirectory[1:]
}
os.MkdirAll(Config.FeedDirectory, 0744)
os.MkdirAll(Config.FeedDirectory, 0644)
Config.Viewer = cfg.Section("settings").Key("viewer").String()
for _, key := range cfg.Section("feeds").Keys() {
Config.Feeds = append(Config.Feeds, Feed{key.String(), cfg.Section("feeds").Key(key.String()).String()})
Expand Down
24 changes: 23 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,32 @@ func main() {
return cmd.Run()
},
},
{
Name: "add",
Aliases: []string{"a"},
Usage: "add a given feed to config",
Action: func(cCtx *cli.Context) error {
if cCtx.Args().Len() != 2 {
return errors.New("exactly two arguments are required, first being feed name, second being URL")
}
homePath, err := os.UserHomeDir()
if err != nil {
log.Error("Failed to get home path")
os.Exit(1)
}
file, err := os.OpenFile(homePath+"/.config/rssnix/config.ini", os.O_APPEND|os.O_WRONLY, 644)
if err != nil {
return err
}
defer file.Close()
_, err = file.WriteString("\n" + cCtx.Args().Get(0) + " = " + cCtx.Args().Get(1))
return err
},
},
},
}

if err := app.Run(os.Args); err != nil {
log.Fatal(err)
log.Error(err)
}
}

0 comments on commit 48fbdc1

Please sign in to comment.