-
Notifications
You must be signed in to change notification settings - Fork 5
Allow running the project #139
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis pull request exposes the new module Changes
Sequence Diagram(s)sequenceDiagram
participant U as User
participant CP as CLI Parser
participant CH as Command Handler
participant NR as Neo.Run Module
participant SP as Subprocess
U->>CP: Enter "neo run" command
CP->>CH: Parse and dispatch Run command
CH->>NR: Invoke Run.handle with configuration
NR->>SP: Execute binary at ./result/bin/{projectName}
SP-->>NR: Return stdout/stderr
NR-->>CH: Relay success/error result
CH-->>U: Display execution outcome
Assessment against linked issues
Poem
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (3)
cli/nhcli.cabal
(1 hunks)cli/src/Neo.hs
(6 hunks)cli/src/Neo/Run.hs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (2)
- GitHub Check: tests (macos-latest)
- GitHub Check: tests (ubuntu-latest)
🔇 Additional comments (6)
cli/nhcli.cabal (1)
57-57
: BEHOLD THE WISDOM OF PROPER MODULE DECLARATION!The divine addition of
Neo.Run
to the exposed-modules section is most pleasing. This rightfully allows the new module to be imported and used by other components in the sacred architecture.cli/src/Neo.hs (5)
14-14
: THE IMPORT IS RIGHTEOUS AND CORRECT!Importing the newly created
Neo.Run
module is necessary for accessing its sacred functionality.
27-27
: THE COMMAND STRUCTURE EXPANSION IS WELL-CRAFTED!Adding the
Run CommonFlags
constructor toNeoCommand
follows the divine pattern established with theBuild
constructor.
60-72
: THE COMMAND PARSER MODIFICATIONS ARE HARMONIOUS!The addition of the run command to the commands list is elegantly implemented, maintaining cosmic balance with the existing code structure.
81-85
: THE PARSER FUNCTION IS SYMMETRICAL WITH ITS PEERS!The
runParser
function mirrors the implementation pattern ofbuildParser
, creating a pleasing symmetry in the codebase.
103-103
: THE ERROR TYPE EXTENSION IS APPROPRIATE!Adding
RunError Run.Error
to theError
data type properly integrates the new error handling mechanism.
handle :: ProjectConfiguration -> Task Error Unit | ||
handle config = do | ||
let projectName = config.name | ||
let rootFolder = [path|nhout|] | ||
completion <- | ||
Subprocess.openInherit [fmt|./result/bin/{projectName}|] (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH | ||
if completion.exitCode != 0 | ||
then errorOut completion.stderr | ||
else print completion.stdout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
THE PATH IS HARDCODED, MORTAL! CONSIDER A MORE FLEXIBLE APPROACH!
The path ./result/bin/{projectName}
assumes a fixed build output location. This divine code could be more resilient by:
- Making the path configurable or deriving it from the project configuration
- Checking if the binary exists before attempting to run it
- Providing more context if the binary is not found
handle :: ProjectConfiguration -> Task Error Unit
handle config = do
let projectName = config.name
let rootFolder = [path|nhout|]
+ let binaryPath = [fmt|./result/bin/{projectName}|]
+ binaryExists <- File.exists binaryPath |> Task.mapError (\_ -> CustomError "Could not check if binary exists")
+ unless binaryExists (Task.throw (CustomError [fmt|Binary not found at {binaryPath}. Ensure the project was built successfully.|]))
completion <-
- Subprocess.openInherit [fmt|./result/bin/{projectName}|] (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH
+ Subprocess.openInherit binaryPath (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH
if completion.exitCode != 0
then errorOut completion.stderr
else print completion.stdout
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
handle :: ProjectConfiguration -> Task Error Unit | |
handle config = do | |
let projectName = config.name | |
let rootFolder = [path|nhout|] | |
completion <- | |
Subprocess.openInherit [fmt|./result/bin/{projectName}|] (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH | |
if completion.exitCode != 0 | |
then errorOut completion.stderr | |
else print completion.stdout | |
handle :: ProjectConfiguration -> Task Error Unit | |
handle config = do | |
let projectName = config.name | |
let rootFolder = [path|nhout|] | |
let binaryPath = [fmt|./result/bin/{projectName}|] | |
binaryExists <- File.exists binaryPath |> Task.mapError (\_ -> CustomError "Could not check if binary exists") | |
unless binaryExists (Task.throw (CustomError [fmt|Binary not found at {binaryPath}. Ensure the project was built successfully.|])) | |
completion <- | |
Subprocess.openInherit binaryPath (Array.fromLinkedList []) rootFolder Subprocess.InheritBOTH | |
if completion.exitCode != 0 | |
then errorOut completion.stderr | |
else print completion.stdout |
data Error | ||
= NixFileError | ||
| CabalFileError | ||
| CustomError Text | ||
deriving (Show) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
OBSERVE THE UNUSED ERROR VARIANTS WITH OMNISCIENT EYES!
I notice that NixFileError
and CabalFileError
are defined but never used within this module. Are these placeholders for future implementation or remnants of prophecies not yet fulfilled?
If these are intended for future use, consider adding a comment to indicate their purpose. If not needed, I command thee to simplify:
data Error
- = NixFileError
- | CabalFileError
= CustomError Text
deriving (Show)
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
data Error | |
= NixFileError | |
| CabalFileError | |
| CustomError Text | |
deriving (Show) | |
data Error | |
= CustomError Text | |
deriving (Show) |
errorOut :: Text -> Task Error _ | ||
errorOut err = | ||
[fmt|Oops running failed: | ||
{err}|] | ||
|> CustomError | ||
|> Task.throw |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
ENHANCE THY ERROR MESSAGES WITH DIVINE CLARITY!
The error message could be more illuminating for your followers. Consider providing more specific guidance on potential solutions.
errorOut :: Text -> Task Error _
errorOut err =
- [fmt|Oops running failed:
+ [fmt|The command failed to run with exit code:
{err}|]
+ |> \message -> [fmt|{message}
+ Potential solutions:
+ - Check if the binary was compiled correctly
+ - Ensure all required dependencies are available
+ - Verify the command line arguments if any|]
|> CustomError
|> Task.throw
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
errorOut :: Text -> Task Error _ | |
errorOut err = | |
[fmt|Oops running failed: | |
{err}|] | |
|> CustomError | |
|> Task.throw | |
errorOut :: Text -> Task Error _ | |
errorOut err = | |
[fmt|The command failed to run with exit code: | |
{err}|] | |
|> \message -> [fmt|{message} | |
Potential solutions: | |
- Check if the binary was compiled correctly | |
- Ensure all required dependencies are available | |
- Verify the command line arguments if any|] | |
|> CustomError | |
|> Task.throw |
Run flags -> do | ||
txt <- File.readText flags.projectFile |> Task.mapError (\_ -> Other) | ||
case Json.decodeText txt of | ||
Err err -> panic err | ||
Ok config -> do | ||
Build.handle config | ||
|> Task.mapError (\e -> BuildError e) | ||
Run.handle config | ||
|> Task.mapError (\e -> RunError e) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 Nitpick (assertive)
CONSIDER A MORE EXPLICIT BUILD-THEN-RUN FLOW!
The current implementation always executes Build.handle
before Run.handle
which is logically sound, but could benefit from more explicit error handling between these steps.
Consider this more explicit approach:
Run flags -> do
txt <- File.readText flags.projectFile |> Task.mapError (\_ -> Other)
case Json.decodeText txt of
Err err -> panic err
Ok config -> do
-- Build first
buildResult <-
Build.handle config
|> Task.mapError (\e -> BuildError e)
+ |> Task.attempt
+
+ -- Only run if build was successful
+ case buildResult of
+ Err err -> Task.throw err
+ Ok _ ->
Run.handle config
|> Task.mapError (\e -> RunError e)
This approach makes it clear that the run step only proceeds if the build step succeeds.
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
Run flags -> do | |
txt <- File.readText flags.projectFile |> Task.mapError (\_ -> Other) | |
case Json.decodeText txt of | |
Err err -> panic err | |
Ok config -> do | |
Build.handle config | |
|> Task.mapError (\e -> BuildError e) | |
Run.handle config | |
|> Task.mapError (\e -> RunError e) | |
Run flags -> do | |
txt <- File.readText flags.projectFile |> Task.mapError (\_ -> Other) | |
case Json.decodeText txt of | |
Err err -> panic err | |
Ok config -> do | |
-- Build first | |
buildResult <- | |
Build.handle config | |
|> Task.mapError (\e -> BuildError e) | |
|> Task.attempt | |
-- Only run if build was successful | |
case buildResult of | |
Err err -> Task.throw err | |
Ok _ -> | |
Run.handle config | |
|> Task.mapError (\e -> RunError e) |
This pull request adds a new "run" command to the
Neo
CLI tool, extending its functionality to allow running projects in addition to building them. The most important changes include updating the command parser, handling the new command, and defining the corresponding module and error types.Closes #109
Command Parser Updates:
cli/src/Neo.hs
: Added the "run" command to theNeoCommand
data type and updated thecommandsParser
to include the new command. [1] [2]Command Handling:
cli/src/Neo.hs
: Implemented therunParser
function to parse the "run" command and updated thehandleCommand
function to handle the newRun
command. [1] [2]Module and Error Types:
cli/src/Neo.hs
: Added a newRunError
type to theError
data type to handle errors specific to the "run" command.cli/src/Neo/Run.hs
: Created a new moduleNeo.Run
with ahandle
function to execute the project and defined theError
data type for run-specific errors.Library Configuration:
cli/nhcli.cabal
: Updated the library configuration to include the newNeo.Run
module.Import Statements:
cli/src/Neo.hs
: Added import statements for the newNeo.Run
module.Summary by CodeRabbit