Skip to content

Commit

Permalink
abstract out the yes/no prompt for use in other modules
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpolzin committed Jul 18, 2023
1 parent 7784399 commit e67350f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/Config.idr
Original file line number Diff line number Diff line change
Expand Up @@ -215,14 +215,14 @@ createConfig envGithubPAT terminalColors editor = do
putStrLn "What GitHub remote repo would you like to use harmony for\{remoteDefaultStr}?"
defaultRemote <- Just . orIfEmpty (Just remoteGuess) . trim <$> getLine

putStr "Would you like harmony to comment when it assigns reviewers? [Y/n] "
commentOnAssign <- yesUnlessNo . trim <$> getLine
commentOnAssign <-
yesNoPrompt "Would you like harmony to comment when it assigns reviewers?"

putStr "Would you like harmony to assign teams when it assigns reviewers? [Y/n] "
assignTeams <- yesUnlessNo . trim <$> getLine
assignTeams <-
yesNoPrompt "Would you like harmony to assign teams when it assigns reviewers?"

putStr "Would you like harmony to assign individual users when it assigns reviewers? [Y/n] "
assignUsers <- yesUnlessNo . trim <$> getLine
assignUsers <-
yesNoPrompt "Would you like harmony to assign individual users when it assigns reviewers?"

_ <- liftIO $ octokit pat
putStrLn "Creating config..."
Expand Down Expand Up @@ -263,12 +263,6 @@ createConfig envGithubPAT terminalColors editor = do
orIfEmpty (Just y) "" = y
orIfEmpty (Just _) x = x

yesUnlessNo : String -> Bool
yesUnlessNo answer with (toLower answer)
_ | "n" = False
_ | "no" = False
_ | _ = True

org : Maybe GitRemote -> Maybe String
org = map (.org)

Expand Down
15 changes: 15 additions & 0 deletions src/Util.idr
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,21 @@ getManyLines = getMoreLines []
("" :: rest, "") => pure (reverse rest)
_ => getMoreLines (line :: acc) fuel

||| Ask a question and receive a yes/no response with yes being the default.
||| You probably want your question String to end with a question mark;
||| @yesNoPrompt@ will append "[Y/n]" to the end of your question for you.
export
yesNoPrompt : HasIO io => (question : String) -> io Bool
yesNoPrompt question = do
putStr "\{question} [Y/n] "
yesUnlessNo . trim <$> getLine
where
yesUnlessNo : String -> Bool
yesUnlessNo answer with (toLower answer)
_ | "n" = False
_ | "no" = False
_ | _ = True

||| Get an absolute path for the given directory or file assuming the
||| given path is relative to the root of the Git repository.
export
Expand Down

0 comments on commit e67350f

Please sign in to comment.