Skip to content

Conversation

pravj
Copy link
Contributor

@pravj pravj commented Jun 11, 2014

it works in this way :

gist --list or gist -l : will check if user is authenticated or not

if user is authenticated : will list all public and private gist urls with description also
if user is not authenticated : warn user to login, using gist --login and exit.

it also takes one optional parameter as username
gist --list abhshkdz will list all public gists of user abhshkdz, it resulted :

[public gists] https://gist.github.com/7460904 : https://gist.github.com/7276887 : Generating a Url slug in PHP https://gist.github.com/5916998 : Music Widget: http://cdpn.io/zvGqf https://gist.github.com/5879343 : Sublime Text 2 Installation Instructions for Ubuntu 13.04 https://gist.github.com/4151814 : Self-updating list of my tweets https://gist.github.com/4148037 : Source nvm + tab completion https://gist.github.com/3940532 : Links Thread https://gist.github.com/3325927 : Building up Hubot on Gtalk (deployed on Heroku) 

@ConradIrwin @rking can you please see this, as it was discussed in issue #168 also
tell me if I need to do anything else ✋

@pravj pravj mentioned this pull request Jun 11, 2014
@dmastylo
Copy link

👍

@pravj
Copy link
Contributor Author

pravj commented Aug 2, 2014

@ConradIrwin can you please review this, am I missing something ?

lib/gist.rb Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should raise a Gist::Error so that it exits with exit status 1: https://github.com/defunkt/gist/blob/master/bin/gist#L164

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

actually this block executes when user is not authenticated and trying to use it like a authed user
gist --list(without providing username)

So, this is just a message to user for help. I can add exit 1 explicitly if you say.
but when I put raise Error, MESSAGE here. It results in

/var/lib/gems/1.9.1/gems/gist-4.2.1/lib/gist.rb:190:in `pretty_gist': Bad credentials (RuntimeError) from /var/lib/gems/1.9.1/gems/gist-4.2.1/lib/gist.rb:141:in `list_gist' from /var/lib/gems/1.9.1/gems/gist-4.2.1/bin/gist:114:in `block (2 levels) in <top (required)>' from /usr/lib/ruby/1.9.1/optparse.rb:1391:in `call' from /usr/lib/ruby/1.9.1/optparse.rb:1391:in `block in parse_in_order' from /usr/lib/ruby/1.9.1/optparse.rb:1347:in `catch' from /usr/lib/ruby/1.9.1/optparse.rb:1347:in `parse_in_order' from /usr/lib/ruby/1.9.1/optparse.rb:1341:in `order!' from /usr/lib/ruby/1.9.1/optparse.rb:1432:in `permute!' from /usr/lib/ruby/1.9.1/optparse.rb:1453:in `parse!' from /var/lib/gems/1.9.1/gems/gist-4.2.1/bin/gist:13:in `<top (required)>' from /usr/local/bin/gist:23:in `load' from /usr/local/bin/gist:23:in `<main>' 

which does not look fine.

can you comment here, please. @ConradIrwin

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, I see the problem. You should do something like:

opts.on("-l", "--list [USER]", "List all gists for user") do |user| options[:list] = user end 

And then inside the begin/rescue/end on https://github.com/defunkt/gist/blob/master/bin/gist#L126 you can do:

if options.key? :list if options[:list] Gist.list_gists(options[:list]) else Gist.list_gists end else # do normal gist stuff here end 

The advantage of raising an error is that then people can use gist as a library in their applications; if we just exit in the middle of running Gist.list_gists, then it's harder for other programmers to handle the error.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool, you are a helpful person 😄
changed it in similar manner as you suggested. all set 👍

@ConradIrwin
Copy link
Collaborator

Hi @pravj! Sorry for the delay. I've added some feedback in-line, please let me know if you need more help.

This will be an awesome feature to have!

> shows file name instead of description > change optparse block in bin/gist
@pravj
Copy link
Contributor Author

pravj commented Aug 5, 2014

Hi @ConradIrwin, I made some changes as you suggested and commented where I need to discuss.
please have a look there.

lib/gist.rb Outdated
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This needs a rescue nil (as above) to handle the case where that file doesn't exist. It might be nicer to refactor this into a method:

def auth_token @auth_token ||= File.read(auth_token_file) rescue "" end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah I noticed this, thanks.

added a new method auth_token which use rescue and returns access token string value or nil if, file is not there.

even changed some part of multi_gist method, which now uses this new method to collect access token.

this is also working fine 👍

@ConradIrwin
Copy link
Collaborator

@pravj Awesome! I think this is getting close :).

pravj added 3 commits August 6, 2014 16:50
> removed header lines for public and private gists.
> now exceptions in middle of execution goes to 'rescue' and exit with status 1
> new method 'auth_token' returns access token string, if it exists or returns 'nil' if access token file is not there.
@pravj
Copy link
Contributor Author

pravj commented Aug 6, 2014

Yo @ConradIrwin,
you really helped me a lot, these small things you mentioned, were not ignorable.

I think I have fixed everything, you asked me.
please have a look here.

and call me if you have any thing else, that you want me to do 😄

@ConradIrwin ConradIrwin merged commit f4c3148 into defunkt:master Aug 6, 2014
@ConradIrwin
Copy link
Collaborator

Merged and released!

I made a few tidy-up commits which you can look at if you like, but you did all the hard work :). Thanks for being patient, and for your excellent contribution! I'm going to be using this all the time.

@pravj
Copy link
Contributor Author

pravj commented Aug 6, 2014

thanks, I'm feeling good now 😄

@pravj
Copy link
Contributor Author

pravj commented Aug 6, 2014

@ConradIrwin Btw in your recent commit 90fb58f
I think lines 150 and 173 will break the Keep lines fewer than 80 characters rule.

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

Labels

None yet

4 participants