-
-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add status command * add --quiet persistent flag to silence * refactor one command or subcommand per files * add --only to enable command Closes #30 Closes #24
- Loading branch information
Showing
21 changed files
with
520 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/guumaster/hostctl/pkg/host" | ||
) | ||
|
||
// addDomainsCmd represents the fromFile command | ||
var addDomainsCmd = &cobra.Command{ | ||
Use: "domains", | ||
Short: "Add content in your hosts file.", | ||
Long: ` | ||
Set content in your hosts file. | ||
If the profile already exists it will be added to it.`, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
profile, _ := cmd.Flags().GetString("profile") | ||
|
||
if profile == "" { | ||
return host.MissingProfileError | ||
} | ||
|
||
if profile == "default" { | ||
return host.DefaultProfileError | ||
} | ||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
src, _ := cmd.Flags().GetString("host-file") | ||
ip, _ := cmd.Flags().GetString("ip") | ||
profile, _ := cmd.Flags().GetString("profile") | ||
quiet, _ := cmd.Flags().GetBool("quiet") | ||
|
||
err := host.AddFromArgs(&host.AddFromArgsOptions{ | ||
Domains: args, | ||
IP: ip, | ||
Dst: src, | ||
Profile: profile, | ||
Reset: false, | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
err = host.Enable(src, profile) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if quiet { | ||
return nil | ||
} | ||
|
||
return host.ListProfiles(src, &host.ListOptions{ | ||
Profile: profile, | ||
}) | ||
}, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/spf13/cobra" | ||
|
||
"github.com/guumaster/hostctl/pkg/host" | ||
) | ||
|
||
// makeListStatusCmd represents the list enabled command | ||
var makeListStatusCmd = func(cmd string) *cobra.Command { | ||
status := "" | ||
switch cmd { | ||
case "enabled": | ||
status = "on" | ||
case "disabled": | ||
status = "off" | ||
} | ||
return &cobra.Command{ | ||
Use: cmd, | ||
Aliases: []string{status}, | ||
Short: fmt.Sprintf("Shows list of %s profiles on your hosts file.", cmd), | ||
Long: fmt.Sprintf(` | ||
Shows a detailed list of %s profiles on your hosts file with name, ip and host name. | ||
`, cmd), | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
src, _ := cmd.Flags().GetString("host-file") | ||
raw, _ := cmd.Flags().GetBool("raw") | ||
cols, _ := cmd.Flags().GetStringSlice("column") | ||
|
||
err := host.ListProfiles(src, &host.ListOptions{ | ||
RawTable: raw, | ||
Columns: cols, | ||
StatusFilter: status, | ||
}) | ||
|
||
return err | ||
}, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
|
||
"github.com/guumaster/hostctl/pkg/host" | ||
) | ||
|
||
// removeDomainsCmd represents the remove command | ||
var removeDomainsCmd = &cobra.Command{ | ||
Use: "domains", | ||
Short: "Remove domains from your hosts file.", | ||
Long: ` | ||
Completely remove domains from your hosts file. | ||
It cannot be undone unless you have a backup and restore it. | ||
`, | ||
PreRunE: func(cmd *cobra.Command, args []string) error { | ||
profile, _ := cmd.Flags().GetString("profile") | ||
|
||
if profile == "" { | ||
return host.MissingProfileError | ||
} | ||
|
||
if profile == "default" { | ||
return host.DefaultProfileError | ||
} | ||
return nil | ||
}, | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
profile, _ := cmd.Flags().GetString("profile") | ||
dst, _ := cmd.Flags().GetString("host-file") | ||
quiet, _ := cmd.Flags().GetBool("quiet") | ||
|
||
err := host.RemoveDomains(dst, profile, args) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
if quiet { | ||
return nil | ||
} | ||
return host.ListProfiles(dst, &host.ListOptions{ | ||
Profile: profile, | ||
}) | ||
}, | ||
} |
Oops, something went wrong.