~nature/yt-cli

086178d6fa0295698f8cf819c91cc326c6664691 — LordNature 1 year, 5 months ago 0f6eb81
main.go: Implemented XDG_CONFIG_DIR.
1 files changed, 27 insertions(+), 11 deletions(-)

M main.go
M main.go => main.go +27 -11
@@ 1,6 1,7 @@
package main

import (
	"log"
	"os"
	"os/exec"
	"io"


@@ 30,8 31,31 @@ list               Lists all videos from subscriptions.
help               Prints usage.
`

// implement xdg standard
const SUB_FILENAME = ".subs"
func init() {
	// Sets XDG_CONFIG_HOME
	CONFIG_DIR, err := os.UserConfigDir()
	if err != nil {
		log.Fatal(err)
	}

	// Create config dir
	CONFIG_DIR += "/yt-cli"
	err = os.MkdirAll(CONFIG_DIR, 0700)
	if err != nil {
		log.Fatal(err)
		return
	}

	// Check if config file exits
	if _, err = os.Stat(CONFIG_DIR + "/channels"); os.IsNotExist(err) {
		err = ioutil.WriteFile(CONFIG_DIR + "/channels", nil, 0600)
		if err != nil {
			log.Fatal(err)
			return
		}
	}
}


func main() {
	var channels []Channel


@@ 68,16 92,8 @@ func main() {

// Appends subscription to file
func addSub(id string) (err error) {
	// Check if file subscription exists
	if _, err = os.Stat(SUB_FILENAME); os.IsNotExist(err) {
		err = ioutil.WriteFile(SUB_FILENAME, nil, 0644)
		if err != nil {
			return
		}
	}

	// Open file in append mode only
	file, err := os.OpenFile(SUB_FILENAME, os.O_APPEND|os.O_WRONLY, 0644)
	file, err := os.OpenFile(SUB_FILENAME, os.O_APPEND|os.O_WRONLY, 0600)
	if err != nil {
		return
	}