-
Notifications
You must be signed in to change notification settings - Fork 116
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
Support for ospath/osstring #491
Comments
I, too, would like this. It's easy enough to provide the conversion on top of the string reader: osPath :: ReadM OsPath
osPath = OA.str >>= \fp -> case OsPath.encodeUtf fp of
Right txt -> pure txt
Left ex -> fail $ "failed: " ++ displayException ex But I imagine you want to skip the conversion entirely. Seems possible to me, but there are some tricky decisions. 1. Implement new getArgs'This would require replacing getArgs :: IO [PosixString]
getArgs =
alloca $ \ p_argc ->
alloca $ \ p_argv -> do
getProgArgv p_argc p_argv
p <- fromIntegral <$> peek p_argc
argv <- peek p_argv
-- base uses 'peekCString :: TextEncoding -> CString -> IO String'
peekArray (p - 1) (advancePtr argv 1) >>= mapM (fmap PS . B.packCString) So, assuming we can just do the same thing for getArgs' :: IO [OsString]
getArgs' =
alloca $ \ p_argc ->
alloca $ \ p_argv -> do
getProgArgv p_argc p_argv
p <- fromIntegral <$> peek p_argc
argv <- peek p_argv
#if WINDOWS
peekArray (p - 1) (advancePtr argv 1) >>= mapM (fmap (OsString . WS) . B.packCString)
#else
peekArray (p - 1) (advancePtr argv 1) >>= mapM (fmap (OsString . PS) . B.packCString)
#endif Armed with this, you have two choices:
Personally, I think 1 is the better solution. 2. Where does
|
It could live in
You want to keep the current behavior of base, which is decodeLE. That can throw an IO exception (same as base). That's as total as the current behavior.
The only sensible way forward is to convert everything to OsString and break the API. Going from String to OsString is pointless and defeats the main purpose of OsString: not assuming encodings! |
For windows getArgs, I added this to Win32: haskell/win32#221 |
Edit: Sorry, missed the first message. I think a Ah, nice. Thanks for pointing that out. So we can obtain It looks like the required parseWord :: String -> Maybe OptWord
parseWord ('-' : '-' : w) = Just $ let
(opt, arg) = case span (/= '=') w of
(_, "") -> (w, Nothing)
(w', _ : rest) -> (w', Just rest)
in OptWord (OptLong opt) arg
parseWord ('-' : w) = case w of
[] -> Nothing
(a : rest) -> Just $ let
arg = rest <$ guard (not (null rest))
in OptWord (OptShort a) arg
parseWord _ = Nothing I presume you'd replicate this with With that in mind, I think you'd probably want to hide this functionality behind a flag, off by default. Normal |
What do you mean by this exactly? Exposed API must not depend on cabal flags. |
When I made that comment, I thought (hoped) that nothing related to the "intended API" would be affected. Sure, Alas, even if that hypothetical plan was palatable (I did say it would be controversial), the details leak in quite a few places, including some exported by the top-level Unfortunately, I think that means we're stuck, at least for some time. Switching to I believe the latest requirement is |
What exactly is the issue with it? filepath is reinstallable, unless you depend on the |
Yes, I was thinking primarily of the unfortunate scenario where one depends on Also, as a nix user, I am keenly aware that it is very difficult to override boot libraries. Effectively it means you wait until you can move to the Like I said, I'd be happy with the change. But I understand if there is reticence. |
Can we have support for
OsPath
/OsString
?The idea of those types is to avoid converting from system (filepath) strings to
String
and back. But currently this is what happens if we want to construct an argument parser that returnsOsPath
.The text was updated successfully, but these errors were encountered: