Skip to content
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

Feature Request: Command to add a dependency/package #8810

Open
andys8 opened this issue Feb 24, 2023 · 11 comments
Open

Feature Request: Command to add a dependency/package #8810

andys8 opened this issue Feb 24, 2023 · 11 comments

Comments

@andys8
Copy link

andys8 commented Feb 24, 2023

Most build tools have a command to add a dependency to your project (e. g. npm install). If I'm not mistaken there currently is no such command in cabal and install and get might be misleading.

Is it possible to add such command? Or is there a reason against or this issue being a duplicate?

Thanks :)

@ffaf1
Copy link
Collaborator

ffaf1 commented Feb 24, 2023

Does cabal build --only-dependencies fit the bill?

 --only-dependencies            Install only the dependencies necessary to
                                build the given packages

@ulysses4ever
Copy link
Collaborator

@andys8 indeed, that would be nice to have. Unfortunately, this is predicated on an ability to read/write .cabal without loss of any information (e.g. user comments, layout, etc.), which is a long-standing task that we have no volunteers for currently. See #7544.

@ulysses4ever
Copy link
Collaborator

@ffaf1 I think you didn't get what they ask for. They want to introduce new dependencies (as in build-depends) from command line rather than editing the .cabal file.

@ulysses4ever
Copy link
Collaborator

Related work is: https://github.com/sdiehl/cabal-edit

@andys8
Copy link
Author

andys8 commented Feb 24, 2023

Unfortunately, this is predicated on an ability to read/write .cabal without loss of any information

@ulysses4ever And is cabal-edit able to do it or is it potentially loosing information?

@ulysses4ever
Copy link
Collaborator

ulysses4ever commented Feb 24, 2023

The latter. It also doesn't support all of the modern features of Cabal, like common stanzas (see its Readme), and it's kinda dormant (doesn't compile with current versions of GHC and Cabal).

@Bodigrim
Copy link
Collaborator

hackage-cli add-bound is an abuse of the tool, but works well.

@gbaz
Copy link
Collaborator

gbaz commented Feb 25, 2023

effectively the same issue #7337

@andreasabel
Copy link
Member

andreasabel commented Feb 27, 2023

hackage-cli add-bound is an abuse of the tool, but works well.

Yeah, a command to add a dependency pays off when you want to bulk-add or script stuff. hackage-cli works in many cases, but does not win a beauty contest. It is good enough for bulk-revising package versions.

In advanced .cabal files, where common stanzas and imports are used, an "add dependency" command might need extra input as to where to place the new dependency, so this is far from trivial to implement. It might only be user friendly with extra intel, like info which .hs modules import from the new dependency. Maybe if the HLS folks have figured out how to do it, it could be backported into cabal...

@Bodigrim
Copy link
Collaborator

I've written https://github.com/Bodigrim/cabal-add. It handles common stanzas reasonably well and allows to specify a target component.

@geekosaur
Copy link
Collaborator

geekosaur commented Oct 20, 2023

This is the kind of use I'd been thinking of for #9063, fwiw. cabal-plan might be another.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants