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

--debug, --username, --server, --password appears to be broken #134

Closed
sepulworld opened this issue Jul 23, 2016 · 18 comments
Closed

--debug, --username, --server, --password appears to be broken #134

sepulworld opened this issue Jul 23, 2016 · 18 comments
Assignees

Comments

@sepulworld
Copy link
Owner

sepulworld commented Jul 23, 2016

Looks like global options in aptly_command.rb are not working presently.

debug_output $stdout L66 in aptly_command.rb doesn't appear to respond and even if you set debug_output $stdout directly in class AptlyCommand it isn't used when running http queries in let's say aptly_repo

$ aptly-cli repo_list --debug --no-config
{"Name"=>"testrepo", "Comment"=>"", "DefaultDistribution"=>"", "DefaultComponent"=>"main"}
{"Name"=>"testrepocreate", "Comment"=>"testing repo creation", "DefaultDistribution"=>"precisecreatetest", "DefaultComponent"=>""}
{"Name"=>"testrepotoshow", "Comment"=>"testing repo show", "DefaultDistribution"=>"preciseshowtest", "DefaultComponent"=>""}
{"Name"=>"testrepo20", "Comment"=>"", "DefaultDistribution"=>"", "DefaultComponent"=>"main"}
{"Name"=>"testrepotoquery", "Comment"=>"testing repo query with name", "DefaultDistribution"=>"precisequerytest", "DefaultComponent"=>""}
{"Name"=>"testrepoedit", "Comment"=>"testing repo edit distro name", "DefaultDistribution"=>"preciseeditdistnew", "DefaultComponent"=>""}

The above command should include HTTP debug output from HTTParty.

@sepulworld sepulworld self-assigned this Jul 23, 2016
@msabramo
Copy link
Contributor

Ah yes, I noticed this too while trying to write a test for --debug. I don't know enough about HTTParty to know how to resolve.

@sepulworld
Copy link
Owner Author

I'll take a look and see if there is a straightforward solution.

@msabramo
Copy link
Contributor

@msabramo
Copy link
Contributor

@sepulworld
Copy link
Owner Author

Would be nice if I didn't have to litter the classes with debug_output $stdout checks, and just have it part of class AptlyCommand

@msabramo
Copy link
Contributor

msabramo commented Jul 23, 2016

Hmm maybe have AptlyCommand extend HTTParty instead of include it?

http://stackoverflow.com/a/14212020/638434

If you extend a class with a module, that means you're "bringing in" the module's methods as class methods. If you include a class with a module, that means you're "bringing in" the module's methods as instance methods.

Though the docs say to use include so I don't know.

@msabramo
Copy link
Contributor

Hmmmm.

jnunemaker/httparty#26

@sepulworld
Copy link
Owner Author

Ok, it might not a problem with the class inheritance.

When I swap out that L66 in aptly_command.rb for

      if self.class.respond_to?(:debug_output)
        puts @config[:debug]
        puts options.debug
        #self.class.debug_output $stdout if @config[:debug]
        self.class.debug_output $stdout
      end

it works. So, it appears to be an issue with the if @config[:debug] check failing. I see that this hash entry is empty at this point, even when I have --debug in the command.

options.debug is true

@sepulworld
Copy link
Owner Author

I think I have boiled it down to

if options.respond_to?(:debug) to passing

@msabramo
Copy link
Contributor

Interesting. Is https://github.com/sepulworld/aptly_cli/blob/master/bin/aptly-cli#L54 getting executed?

@sepulworld
Copy link
Owner Author

sepulworld commented Jul 23, 2016

It is... when I do some 'puts' debugging I see it come through.

When I inspect the 'options' object

puts options.inspect
<Commander::Command::Options debug=true, no_config=false>

puts options.respond_to?(:debug)

returns empty line

@msabramo
Copy link
Contributor

I wonder if the commander Options class might have its own debug method that we're clashing with?

@msabramo
Copy link
Contributor

If I were at a keyboard, I think I'd put a require 'pry'; binding.pry where $debug gets set.

@sepulworld
Copy link
Owner Author

Maybe, but I also see similar behavior with other options.

if options.respond_to?(:server)

Looks like they are all missed upon respond_to? check. Using Ruby 2.3.0...

@sepulworld
Copy link
Owner Author

Ok, Ill checkout with pry, good call.

@sepulworld sepulworld changed the title --debug appears to be broken --debug, --username, --server, --password appears to be broken Jul 23, 2016
@sepulworld
Copy link
Owner Author

sepulworld commented Jul 23, 2016

So, I think why the tests passed originally is because we create the options object with Options.new and get an object that looks like this.

responds_to? works for this object...
#<Options:0x007f964662d688 @username="me", @password="secret", @server="my-server", @port=9000, @debug=false>

versus in aptly_command.rb the options object comes from Commander and inspect (seen in pry) shows it as:

responds_to? doesn't work for us here....
<Commander::Command::Options debug=true, no_config=false, server="127.0.0.1">

@msabramo
Copy link
Contributor

Fixed by #137 ?

@sepulworld
Copy link
Owner Author

Yes, looks good. I'll close this and work on some functional test using serverspec.

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

No branches or pull requests

2 participants