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

cargo-init would be super nice #21

Closed
lightsofapollo opened this issue Jun 14, 2014 · 30 comments
Closed

cargo-init would be super nice #21

lightsofapollo opened this issue Jun 14, 2014 · 30 comments
Labels

Comments

@lightsofapollo
Copy link

Something like cargo-init to bootstrap a new project would be very nice (mainly creating the toml file if it does not exist and maybe other flags in the future)

@wycats
Copy link
Contributor

wycats commented Jun 21, 2014

Indeed it would be. On it!

@thiagopnts
Copy link

Would it be something like rust-empty or more cargo specific?

@alexcrichton alexcrichton mentioned this issue Jun 24, 2014
@steveklabnik
Copy link
Member

@thiagopnts Cargo is a replacement for rust-empty. It would be cargo-specific. My understanding is that rust-empty has a 'transition to Cargo' feature of some kind...

@commonquail
Copy link

From the alpha announcement:

  • cargo package <name> to create a new package skeleton

Is it correctly understood that cargo package <name> would be the solution to this issue? If so, I associate a different meaning -- that of preparing for distribution -- with package, and I don't think that's an intuitive name for the command. I think init, if for no other reason than consistency with several other tools with similar functionality, is a better fit.

@steveklabnik
Copy link
Member

I think we actually decided on cargo project, and that's a typo, but I could be wrong.

@tomjakubowski
Copy link
Contributor

project is a poor choice to me because the other subcommands are all verbs, and "project" as a verb doesn't map well to what this command is doing.

@tomjakubowski
Copy link
Contributor

(unless you mean it's like... a projection of some abstract directory structure onto the filesystem)

@seanmonstar
Copy link

+1 cargo init. Previously: npm init?

@thiagopnts
Copy link

what about cargo new?

@tomjakubowski
Copy link
Contributor

Prior art includes:

  • npm init - creates a package.json file, with interactive prompts for package name/license and such
  • lein new [template-name] <project-name> - creates a new folder containing a skeleton project, optionally from a template, including a project.clj file
  • cabal init - creates a skeleton Setup.hs and project_name.cabal in the current directory, with interactive prompts

@mavdi
Copy link

mavdi commented Jul 6, 2014

+1 I miss npm init

@jimfleming
Copy link

Just throwing this in, git init would be another established example.

@wycats
Copy link
Contributor

wycats commented Jul 8, 2014

git init initializes an existing directory, as does bundle init. We may want to have an analogue to that and use cargo new to create a new directory that is already cargoified.

@nielsle
Copy link
Contributor

nielsle commented Jul 14, 2014

Perhaps allow the user to choose between cargo init --template=bin and cargo init --template=lib to enforce standards.

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Jul 22, 2014
This command is used to create a new cargo repository at a destination that
previously does not exist. A separate command, cargo-init, will be implemented
to initialize an already-existing repository.

cc rust-lang#21
bors added a commit that referenced this issue Jul 22, 2014
This command is used to create a new cargo repository at a destination that
previously does not exist. A separate command, cargo-init, will be implemented
to initialize an already-existing repository.

cc #21

This is currently rebased on #238
@steveklabnik
Copy link
Member

This should be fixed now, yes?

@alexcrichton
Copy link
Member

I'd like to keep this open for now to keep as a reminder for a cargo-init command which takes an existing directory and cargo-ifies it (more complicated though)

@steveklabnik
Copy link
Member

I'd vote for cargo new . to do that, but sure.

alexcrichton added a commit to alexcrichton/cargo that referenced this issue Sep 2, 2014
This command is used to create a new cargo repository at a destination that
previously does not exist. A separate command, cargo-init, will be implemented
to initialize an already-existing repository.

cc rust-lang#21
@andrewrk
Copy link

The existing directory case is much more common than the new case. So far every time I've used cargo new it's looked like this (cursing and expletives removed):

~/dev/my-rust-project$ cargo new
Usage:
    cargo new [options] <path>
    cargo new -h | --help
~/dev/my-rust-project$ cargo new .
Destination `~/dev/my-rust-project` already exists
~/dev/my-rust-project$ cargo new my-rust-project
~/dev/my-rust-project$ ls
my-rust-project
$ mv my-rust-project/ ../
mv: overwrite ‘../my-rust-project’? n
~/dev/my-rust-project$ cd ..
~/dev$ mv my-rust-project/ aoeuaoeu
~/dev$ mv aoeuaoeu/my-rust-project/ ./
~/dev$ cp -r aoeuaoeu/* my-rust-project/
~/dev$ rmdir aoeuaoeu/
~/dev$ cd my-rust-project/

Not a positive user experience, to say the least.

@kornelski
Copy link
Contributor

I've ran into this when I wanted to convert a C toy project to rust.

I don't want any fancy autocargoification. I just want a template for Cargo.toml, because I don't remember its syntax.

@ArielCabib
Copy link

@andrewrk If you're working under *nix, run

cargo new tmp --bin
mv tmp/Cargo.toml tmp/.git tmp/.gitignore tmp/src .
rmdir tmp

It's ugly, but it works

@andrewrk
Copy link

@ArielCabib so, getting the project working at all is not an issue. The issue is that it could be much more straightforward. Hence, this issue filed on the cargo project. Thanks for providing a workaround, but it misses the point.

@shaleh
Copy link

shaleh commented Aug 28, 2015

Is there opposition to this? I am willing to submit a pull request if it will be accepted.

Do we want cargo new --dir . or is cargo init as suggested above ok?

My work flow looks a lot like @andrewrk's.

@kornelski
Copy link
Contributor

@shaleh is the --dir necessary? I hoped the logic would be that if the argument to new is a path that exists, then filename part of resolved path is used, so that cd foo; cargo new . and cargo new /baz/foo/ create a foo project.

@shaleh
Copy link

shaleh commented Aug 29, 2015

No it is not needed. It was offered to start the conversation.

On August 29, 2015 5:22:14 AM PDT, Kornel notifications@github.com wrote:

@shaleh is the --dir necessary? I hoped the logic would be that if
the argument to new is a path that exists, then filename part of
resolved path is used, so that cd foo; cargo new . and cargo new /baz/foo/ create a foo project.


Reply to this email directly or view it on GitHub:
#21 (comment)

Sent from my Android phone with K-9 Mail. Please excuse my brevity.

vi added a commit to vi/cargo that referenced this issue Sep 29, 2015
Allows "new" command even if path exists,
if the path is empty or almost empty directory.

Also more narrow duplicates: rust-lang#1990, rust-lang#1065, rust-lang#526.
bors added a commit that referenced this issue Jan 24, 2016
Implement `cargo init` command and appropriate tests ( #21).

Features:
* Working like `cargo new` if there are no files in current directory
* Auto-detection of `--bin`
* Auto-detection of already existing VSC and appending to respecive ignore file
* Appending of appropriate `[lib]` or `[[bin]]` section to `Cargo.toml` in case of some non-standard source locations

Concerns:
* I'm not experienced in Rust + lazy => code looks poorer compared to the rest Cargo code
* The test don't cover 100% of functions
* Project consisting of both binary and library is not handled
* Many deviations from [previously proposed algorithm](#2008 (comment))
@rasendubi
Copy link

Now when #2081 is merged, this issue can be finally closed?

@alexcrichton
Copy link
Member

Thanks for the reminder @rasendubi, and thanks again @vi for the implementation!

@shaleh
Copy link

shaleh commented Jan 25, 2016

yay!! Bummed my life got in the way but happy someone else stepped in.

@e-oz
Copy link

e-oz commented Nov 22, 2016

cargo init still can't init project in existing folder, not sure why this issue is closed.

Rust beta 14, macos sierra:

OZ:repositories OZ$ cd feed_importer/
OZ:feed_importer OZ$ cargo init feed_importer --bin --vcs none
OZ:feed_importer OZ$ ls
feed_importer
OZ:feed_importer OZ$ ls feed_importer/
Cargo.toml src

@carols10cents
Copy link
Member

@e-oz It looks like you specified a path, but it seems like you wanted to use the current directory. Instead of cargo init feed_importer --bin --vcs none, what if you run cargo init --bin --vcs none?

@e-oz
Copy link

e-oz commented Nov 22, 2016

@carols10cents I thought I specified package.name. Thank you, without name everything works fine. Sorry for false report.

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

No branches or pull requests