Skip to content

Commit 67ba39c

Browse files
authored
Merge pull request #1 from pablotrianda/feat_using_args
Feat using args
2 parents 4a6642d + 8333605 commit 67ba39c

File tree

4 files changed

+26
-53
lines changed

4 files changed

+26
-53
lines changed

cmd/config/main.go

+3-43
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,7 @@
11
package 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-
123
type 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
}

cmd/pomodorox/actions.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,17 @@ func printInfo(pomo *Pomodorox) {
3939

4040
func 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,

install.sh

-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ cp pomodorox "$HOME/.local/bin/"
77
echo "🍅 Copy assets folder."
88
cp assets/tomato.png "$HOME/.local/share/icons/"
99
echo "🍅 Create a config file."
10-
mkdir -p "$HOME/.config/pomodorox/"
11-
cp config_sample.yaml "$HOME/.config/pomodorox/config.yaml"
1210
echo "DONE 😎"
1311

1412

main.go

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,29 @@
11
package main
22

33
import (
4+
"fmt"
5+
"os"
6+
"strconv"
7+
48
"github.com/pablotrianda/pomodox/cmd/config"
59
"github.com/pablotrianda/pomodox/cmd/pomodorox"
610
)
711

812
func 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
}

0 commit comments

Comments
 (0)