guumaster / hostctl

Your dev tool to manage /etc/hosts like a pro!
http://guumaster.github.io/hostctl
MIT License
1.05k stars 45 forks source link

Wait Flag #32

Closed smhmd closed 4 years ago

smhmd commented 4 years ago

Is your feature request related to a problem? Please describe. blocking websites to work, I sometimes need to use a website for a limited amount of time to not sidetrack. Do you think it would be useful to add a time flag?

Describe the solution you'd like

$ hostctl enable -p youtube -t 15 # enable youtube profile for 15 minutes

Describe alternatives you've considered

$ hostcl enable -p youtube && sleep 900 && hostctl disable -p youtube
guumaster commented 4 years ago

I was thinking on something similar like --wait to keep the command running and stop on CRTL+c, but it could also accept a time parameter. I like the idea.

guumaster commented 4 years ago

This is implemented on v0.10.0. Thanks for adding this request @smhmd! :tada:

You can use it with this examples:

# enable awesome profile for 30 seconds and then disable it (or until ctrl-c)
hostctl enable -p youtube --wait 30s

# add a new profile with content from a file and disable it after 8 hours (or until ctrl-c)
hostctl add -p dailyblock --from $HOME/block_daily_hosts --wait 8h   

# sync with docker-compose services and remove them when ctrl-c is sent
hostctl sync docker-compose --wait 0 
smhmd commented 4 years ago

@guumaster wait flag for toggle command?

smhmd commented 4 years ago

@guumaster --wait without argument to assume 0?

guumaster commented 4 years ago

I've tried that, but with the CLI framework cobra, AFAIK you can't have a flag with two types (duration or bool), so I've chosen the duration option and that makes the zero mandatory to wait indefinitely.