Add functionality to accept setting status non-interactively
parent
69f41ad157
commit
48b89eaff5
38
main.go
38
main.go
|
@ -100,10 +100,17 @@ func SetStatus(args []string) error {
|
||||||
// User status is written to ~/.checkin
|
// User status is written to ~/.checkin
|
||||||
outputPath := path.Join(curUser.HomeDir, ".checkin")
|
outputPath := path.Join(curUser.HomeDir, ".checkin")
|
||||||
|
|
||||||
// Prompt user for input
|
var input string
|
||||||
input, err := PromptInput()
|
|
||||||
if err != nil {
|
// Check if input was provided on the command line.
|
||||||
return err
|
if len(setFlags.Args()) > 0 {
|
||||||
|
input = ArgsToStatus(setFlags.Args(), curUser)
|
||||||
|
} else {
|
||||||
|
// Prompt user for input
|
||||||
|
input, err = PromptInput()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Remove file on blank input
|
// Remove file on blank input
|
||||||
|
@ -137,6 +144,29 @@ func SetStatus(args []string) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ArgsToStatus concatenates all arguments left over from a call to flag.Parse
|
||||||
|
// and returns it as a well-formed status.
|
||||||
|
func ArgsToStatus(args []string, curUser *user.User) string {
|
||||||
|
status := strings.Join(args, " ")
|
||||||
|
status = strings.TrimRight(status, " \n\t\r")
|
||||||
|
if status == "" {
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(status, "~"+curUser.Username) {
|
||||||
|
return status
|
||||||
|
}
|
||||||
|
|
||||||
|
if strings.HasPrefix(status, curUser.Username) {
|
||||||
|
return "~" + status
|
||||||
|
}
|
||||||
|
|
||||||
|
return fmt.Sprintf("~%s: %s", curUser.Username, status)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetFriendlyWd returns the friendliest equivalent to the working directory.
|
||||||
|
// If we're in the user's home directory, we return a path relative to ~user.
|
||||||
|
// If we're in that user's public_html directory, we return an http link to it.
|
||||||
func GetFriendlyWd(curUser *user.User) (string, error) {
|
func GetFriendlyWd(curUser *user.User) (string, error) {
|
||||||
wd, err := os.Getwd()
|
wd, err := os.Getwd()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue