File tree Expand file tree Collapse file tree 4 files changed +26
-53
lines changed
Expand file tree Collapse file tree 4 files changed +26
-53
lines changed Original file line number Diff line number Diff line change 11package config
22
3- import (
4- "io/ioutil"
5- "os"
6-
7- "gopkg.in/yaml.v3"
8- )
9-
10- const CONFIG_PATH = "/.config/pomodorox/config.yaml"
11-
123type Config struct {
13- Timers struct {
14- WorkLoops int `yaml:"workLoops"`
15- TimeWorkLoops int `yaml:"timeWorkLoops"`
16- TimePause int `yaml:"timePause"`
17- }
18- }
19-
20- func getConf (file []byte ) (* Config , error ) {
21- conf := & Config {}
22- err := yaml .Unmarshal (file , conf )
23- if err != nil {
24- return nil , err
25- }
26-
27- return conf , nil
28- }
29-
30- func openConfigFile () []byte {
31- homePath := os .Getenv ("HOME" )
32- file , err := ioutil .ReadFile (homePath + CONFIG_PATH )
33- if err != nil {
34- panic (err )
35- }
36-
37- return file
38- }
39-
40- func GetConf () (* Config , error ) {
41- conf , err := getConf (openConfigFile ())
42- if err != nil {
43- return nil , err
44- }
45-
46- return conf , nil
4+ TimeWork int
5+ TimePause int
6+ QtyWorkLoops int
477}
Original file line number Diff line number Diff line change @@ -39,17 +39,17 @@ func printInfo(pomo *Pomodorox) {
3939
4040func StartPomodorox (config * config.Config ) {
4141 work := timeLoop {
42- loops : config .Timers . WorkLoops ,
42+ loops : config .QtyWorkLoops ,
4343 completedLoops : 0 ,
4444 }
4545
4646 pause := timeLoop {
47- loops : config .Timers . WorkLoops - 1 ,
47+ loops : config .QtyWorkLoops - 1 ,
4848 completedLoops : 0 ,
4949 }
5050
51- workTime := time .Duration (config .Timers . TimeWorkLoops )
52- pauseTime := time .Duration (config .Timers . TimePause )
51+ workTime := time .Duration (config .TimeWork )
52+ pauseTime := time .Duration (config .TimePause )
5353
5454 pomo := Pomodorox {
5555 workLoops : work ,
Original file line number Diff line number Diff line change @@ -7,8 +7,6 @@ cp pomodorox "$HOME/.local/bin/"
77echo " 🍅 Copy assets folder."
88cp assets/tomato.png " $HOME /.local/share/icons/"
99echo " 🍅 Create a config file."
10- mkdir -p " $HOME /.config/pomodorox/"
11- cp config_sample.yaml " $HOME /.config/pomodorox/config.yaml"
1210echo " DONE 😎"
1311
1412
Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "fmt"
5+ "os"
6+ "strconv"
7+
48 "github.com/pablotrianda/pomodox/cmd/config"
59 "github.com/pablotrianda/pomodox/cmd/pomodorox"
610)
711
812func main () {
9- config , err := config . GetConf ()
10- if err != nil {
11- panic ( err )
13+ if ! ( len ( os . Args ) > 1 ) {
14+ fmt . Println ( "YOU MUST USE PARAMS!!" )
15+ os . Exit ( 1 )
1216 }
13- pomodorox .StartPomodorox (config )
17+
18+ timeWork , _ := strconv .Atoi (os .Args [1 ])
19+ timePause , _ := strconv .Atoi (os .Args [2 ])
20+ qtyWorkLoops , _ := strconv .Atoi (os .Args [3 ])
21+
22+ conf := & config.Config {
23+ TimeWork : timeWork ,
24+ TimePause : timePause ,
25+ QtyWorkLoops : qtyWorkLoops ,
26+ }
27+
28+ pomodorox .StartPomodorox (conf )
1429}
You can’t perform that action at this time.
0 commit comments