-
Notifications
You must be signed in to change notification settings - Fork 721
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
Simplify socket path code #5120
Conversation
fb637c6
to
1388ee2
Compare
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.
I'll go out on a limb and claim that it is never necessary to use unsafePerformIO
in application code. And most uses do bite you in the end (often when refactoring later).
We should just do it properly.
I understand that most uses case bite you in the end, but the one use case we're you using it to initialise a constant that never changes isn't one of them and I never use it for any other reason. |
Our attitude should be to simply not use it (in application code), rather than looking for justification as to why it might not be so bad in this or that case. It's not "Haskell". It has no semantics. |
e32722d
to
9d8517a
Compare
The code no longer uses |
9c9d7c5
to
9e44345
Compare
03785be
to
c71ab32
Compare
c71ab32
to
a11f750
Compare
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.
Nice 👍. Just one comment for you to consider.
, Opt.help $ mconcat | ||
[ "Path to the node socket. This overrides the CARDANO_NODE_SOCKET_PATH " | ||
, "environment variable" | ||
pSocketPath :: EnvCli -> Parser SocketPath |
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.
Why not leverage (<|>)?:Alternative
pSocketPath :: EnvCli -> Parser SocketPath
pSocketPath envCli =
let opts = mconcat
[ Opt.long "socket-path"
, Opt.metavar "SOCKET_PATH"
, Opt.help $ mconcat
[ "Path to the node socket. This overrides the CARDANO_NODE_SOCKET_PATH "
, "environment variable"
]
, Opt.completer (Opt.bashCompleter "file")
]
in fmap SocketPath (Opt.strOption opts) <|>
-- Default to the socket path specified by the environment variable if it is available.
pure (maybe (error "No socket path specified via cli nor env var") SocketPath $ envCliSocketPath envCli)
And then we can error
immediately rather than the networking code throw some obscure error.
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.
We already use Alternative
via asum
. If CARDANO_NODE_SOCKET_PATH
is not supplied, the code as it currently is will error immediately because --socket-path
is the only Alternative
in this case. The CLI parsing will fail because --socket-path
is not supplied and it is the only alternative. You only get the fallback alternative if CARDANO_NODE_SOCKET_PATH
is supplied, in which case the socket path provided by the environment variable is the default and --socket-path
will override.
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.
I updated the CLI help message to be clearer.
a11f750
to
9a195fb
Compare
Instead of reading
CARDANO_NODE_SOCKET_PATH
in every command, do it once inmain
and then use it as a default value in--socket-path
option if available.Also read
CARDANO_NODE_NETWORK_ID
and use that if neither--testnet-magic
nor--mainnet
supplied.