luvit / lit

Toolkit for developing, sharing, and running luvit/lua programs and libraries.
http://lit.luvit.io/
Apache License 2.0
245 stars 58 forks source link

Error while running lit init on Windows. #156

Closed xpol closed 8 years ago

xpol commented 8 years ago

I just installed lit on Windows and run lit init got the follow error:

e:\home\xpol\myproject>lit init
lit version: 3.0.0
luvi version: v2.5.2
command: init
create config: D:\Users\xpol\AppData\Roaming\litconfig
Output to package.lua (1), or a init.lua (2)?: 1
Creating: package.lua
fail: [string "bundle:commands/init.lua"]:70: attempt to concatenate field 'username' (a nil value)
stack traceback:
        [string "bundle:commands/init.lua"]:70: in function <[string "bundle:commands/init.lua"]:1>
        [string "bundle:main.lua"]:52: in function <[string "bundle:main.lua"]:39>
        [C]: in function 'xpcall'
        [string "bundle:main.lua"]:39: in function <[string "bundle:main.lua"]:31>
xpol commented 8 years ago

Sorry I'm tested on windows and I never use ssh key...

creationix commented 8 years ago

Looks like we could use some better error reporting here. But you will be unable to publish to the lit server without an ssh key tied to your github account.

As far as username, lit-init should prompt for any missing data instead of crashing. @james2doyle or @squeek502, do either of you have a moment to help with this?

james2doyle commented 8 years ago

Yeah I have a minute

james2doyle commented 8 years ago

Should this new check or guard be added to commands/init.lua?

Lit init calls core.config, and core.config calls autoconfig, so I'm not sure where to do this check.

creationix commented 8 years ago

Autoconfig shouldn't require a username since it's global. The init command should prompt for it if missing like the auth command does.

squeek502 commented 8 years ago

This patch should work:

@@ -65,11 +65,12 @@ return function ()
     -- trim trailing comma and space
     tags = tags:sub(0, (#tags - 2))
     return tags .. " }"
   end

-  local projectName = prompt("Project Name", config["username"] .. "/project-name")
+  local userName = prompt("Username", config["username"])
+  local projectName = prompt("Project Name", userName .. "/project-name")
   local projectVersion = prompt("Version", "0.0.1")
   local projectDescription = prompt("Description", "A simple description of my little package.")
   local projectTags = makeTags(prompt("Tags (Comma Separated)", "lua, lit, luvit"))
   local authorName = prompt("Author Name", getConfig("user.name"))
   local authorEmail = prompt("Author Email", getConfig("user.email"))

Let me know if you'd like me to submit it as a PR.

james2doyle commented 8 years ago

@squeek502 Stolen!

squeek502 commented 8 years ago

:smile:

Here's an alternative fix, because username isn't actually used for anything except the project name prompt:

-  local projectName = prompt("Project Name", config["username"] .. "/project-name")
+  local projectName = prompt("Project Name", (config["username"] or "username") .. "/project-name")

Not sure which is better. Here's a comparison between what the prompts look like when config["username"] is nil.

First fix:

Creating: package.lua
Username: squeek502
Project Name: (squeek502/project-name) squeek502/test

Alt fix:

Creating: package.lua
Project Name: (username/project-name) squeek502/test
james2doyle commented 8 years ago

I like the first fix personally. It emulates how npm|bower init work

xpol commented 8 years ago

@creationix

Added ssh key under windows works for me. We should add a setup instructions in https://luvit.io/install.html (or a seprated guide), some steps like.

  1. Install git for windows.
  2. Follow the guide here https://help.github.com/articles/generating-ssh-keys/#platform-windows to add a SSH key.
  3. lit auth <you github username>