Utils.pm 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # ABSTRACT: Utilities for the testrail command line functions.
  2. # PODNAME: TestRail::Utils
  3. =head1 DESCRIPTION
  4. Utilities for the testrail command line functions.
  5. =cut
  6. package TestRail::Utils;
  7. use strict;
  8. use warnings;
  9. =head1 FUNCTIONS
  10. =head2 userInput
  11. Wait for user input and return it.
  12. =cut
  13. sub userInput {
  14. local $| = 1;
  15. my $rt = <STDIN>;
  16. chomp $rt;
  17. return $rt;
  18. }
  19. =head2 parseConfig(homedir)
  20. Parse .testrailrc in the provided home directory.
  21. Returns:
  22. ARRAY - (apiurl,password,user)
  23. =cut
  24. sub parseConfig {
  25. my ($homedir,$login_only) = @_;
  26. my $results = {};
  27. my $arr =[];
  28. open(my $fh, '<', $homedir . '/.testrailrc') or return (undef,undef,undef);#couldn't open!
  29. while (<$fh>) {
  30. chomp;
  31. @$arr = split(/=/,$_);
  32. if (scalar(@$arr) != 2) {
  33. warn("Could not parse $_ in '$homedir/.testrailrc'!\n");
  34. next;
  35. }
  36. $results->{lc($arr->[0])} = $arr->[1];
  37. }
  38. close($fh);
  39. return ($results->{'apiurl'},$results->{'password'},$results->{'user'}) if $login_only;
  40. return $results;
  41. }
  42. 1;
  43. __END__
  44. =head1 SPECIAL THANKS
  45. Thanks to cPanel Inc, for graciously funding the creation of this module.