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

add dpaste plugin #170

Closed
wants to merge 15 commits into from
Closed

add dpaste plugin #170

wants to merge 15 commits into from

Conversation

rominf
Copy link
Contributor

@rominf rominf commented Jun 8, 2014

Just a dpaste (https://github.com/bartTC/dpaste) wrapper

@bpinto
Copy link
Member

bpinto commented Jun 11, 2014

➜ .oh-my-fish git:(rominf-dpaste) dpaste
➜ .oh-my-fish git:(rominf-dpaste) dpaste --help
➜ .oh-my-fish git:(rominf-dpaste)

Nothing being printed. Something I'm doing wrong?

@rominf
Copy link
Contributor Author

rominf commented Jun 11, 2014

Well, I forgot to add --help option (I added only -h), but I don't understand why it don't show anything for you. It's wrong. Can you check your sed? Does it have -r option ("normal" regexp)?

@bpinto
Copy link
Member

bpinto commented Jun 11, 2014

My sed does not have -r options. I'm running Maverick (osx).

➜ .oh-my-fish git:(rominf-dpaste) sed -
-a  (Delay opening files until a command containing the related 'w' function is applied)  -e  (Evaluate expression)  -i  (Edit files in place)  -n  (Silent mode)
-E                                                                 (Use extended regexp)  -f         (Evalute file)  -l   (Use line buffering)
➜ .oh-my-fish git:(rominf-dpaste) dpaste --help
Usage:
  dpaste [-t EXPIRES] < README.md
  dpaste [-t EXPIRES] README.md
  cat README.md | dpaste [-t EXPIRES]
  dpaste [-t EXPIRES] "I \<3 to paste"

Options:
  -t EXPIRES  set snippet expiration time: (onetime|never|hour|week|month) [default: month]

➜ .oh-my-fish git:(rominf-dpaste) dpaste
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]
sed: illegal option -- r
usage: sed script [-Ealn] [-i extension] [file ...]
       sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]

@KamilaBorowska
Copy link

sed -r is GNU extension. You may want to fix your script to not depend on sed -r.

@rominf
Copy link
Contributor Author

rominf commented Jun 11, 2014

Writing with standard POSIX regexes is painful as hell (consider: \(never\|onetime\|hour\)). I adopted advice describing extended regexes usage in other OS. Can you please try it again? To simplify it I provided tests. Install https://github.com/terlar/fish-tank as described and run fish plugins/dpaste/tests/test_dpaste.fish.

Thank you, @terlar for providing unit testing framework!

@bpinto
Copy link
Member

bpinto commented Jun 11, 2014

Tests are great! I'll take a look at fish-tank.

Why not use -E always?

@rominf
Copy link
Contributor Author

rominf commented Jun 11, 2014

Well, there is no reason to use -r instead of -E in this situation. I just messed up with tests and thought that they don't work because of -E flag. Now I'm using -E everywhere.

@bpinto
Copy link
Member

bpinto commented Jun 11, 2014

It hangs forever when dpaste is called without arguments.

@rominf
Copy link
Contributor Author

rominf commented Jun 12, 2014

Do tests work?
Well, I don't have ideas how to debug this issue.
BTW how can I log via stderr? I know how I can check for variable and how to echo to stderr. But it's cumbersome to do this in every line of logging. Is there something like Python's logging facilities?

@bpinto
Copy link
Member

bpinto commented Jul 16, 2014

I still need to test this.

@bpinto
Copy link
Member

bpinto commented Aug 15, 2014

Sorry that I took so long! I really enjoy this plugin.

➜ .oh-my-fish git:(master) fish plugins/dpaste/tests/test_dpaste.fish

# Running:

source: Error encountered while sourcing file '../dpaste.fish':
source: No such file or directory
fish: Unknown command '__dpaste_set_defaults'
- (line 3):     __dpaste_set_defaults
                ^
in function 'setup'
    called on line 19 of file /usr/local/share/fish-tank/functions/__tank_run_tests.fish

in function '__tank_test_setup'
    called on line 2 of file /usr/local/share/fish-tank/functions/__tank_run_tests.fish
    with parameter list 'test_dpaste_parse_expires'

in event handler: handler for generic event 'test_run'

fish: Unknown command '__dpaste_parse_expires'
- (line 1): __dpaste_parse_expires text
            ^
in command substitution
    called on line 6 of file -

in function 'test_dpaste_parse_expires'
    called on line 1 of file -

from sourcing file -
    called on line 35 of file /opt/boxen/homebrew/Cellar/fish/HEAD/share/fish/functions/eval.fish

in function 'eval'
    called on line 10 of file /usr/local/share/fish-tank/functions/__tank_run_tests.fish

in function '__tank_run_tests'
    called on line 5 of file /usr/local/share/fish-tank/functions/tank_run_suite.fish
    with parameter list 'suite_dpaste'

in function 'tank_run_suite'
    called on line 11 of file /usr/local/share/fish-tank/functions/tank_run.fish
    with parameter list 'suite_dpaste'

in function 'tank_run'
    called on line 25 of file ~/.oh-my-fish/plugins/dpaste/tests/test_dpaste.fish

fish: Unknown command '__dpaste_parse_expires'
- (line 1): __dpaste_parse_expires -t never text
            ^
in command substitution
    called on line 6 of file -

in function 'test_dpaste_parse_expires'
    called on line 1 of file -

from sourcing file -
    called on line 35 of file /opt/boxen/homebrew/Cellar/fish/HEAD/share/fish/functions/eval.fish

in function 'eval'
    called on line 10 of file /usr/local/share/fish-tank/functions/__tank_run_tests.fish

in function '__tank_run_tests'
    called on line 5 of file /usr/local/share/fish-tank/functions/tank_run_suite.fish
    with parameter list 'suite_dpaste'

in function 'tank_run_suite'
    called on line 11 of file /usr/local/share/fish-tank/functions/tank_run.fish
    with parameter list 'suite_dpaste'

in function 'tank_run'
    called on line 25 of file ~/.oh-my-fish/plugins/dpaste/tests/test_dpaste.fish

fish: Unknown command '__dpaste_parse_expires'
- (line 1): __dpaste_parse_expires -t hour text
            ^
in command substitution
    called on line 6 of file -

in function 'test_dpaste_parse_expires'
    called on line 1 of file -

from sourcing file -
    called on line 35 of file /opt/boxen/homebrew/Cellar/fish/HEAD/share/fish/functions/eval.fish

in function 'eval'
    called on line 10 of file /usr/local/share/fish-tank/functions/__tank_run_tests.fish

in function '__tank_run_tests'
    called on line 5 of file /usr/local/share/fish-tank/functions/tank_run_suite.fish
    with parameter list 'suite_dpaste'

in function 'tank_run_suite'
    called on line 11 of file /usr/local/share/fish-tank/functions/tank_run.fish
    with parameter list 'suite_dpaste'

in function 'tank_run'
    called on line 25 of file ~/.oh-my-fish/plugins/dpaste/tests/test_dpaste.fish

Eexpr: not a decimal number: '1408071782N'
(standard_in) 1: parse error


Finished in 0s

  1) Error:
suite_dpaste#test_dpaste_parse_expires:
Wrong number of arguments

1 runs, 1 assertions, 0 failures, 1 errors, 0 skips

@bpinto
Copy link
Member

bpinto commented Aug 15, 2014

Something I noticed is that there is no completion when you do a dpaste - TAB. It would be a nice addition.

@rominf
Copy link
Contributor Author

rominf commented Aug 15, 2014

Something I noticed is that there is no completion when you do a dpaste - TAB.

I wanted to make this plugin user-friendly (in terms of arguments processing). But then I realized that it's harder work than in python, for example, because of lack of argument parsing framework. I will wait until fish-shell/fish-shell#478 will be closed.

@rominf
Copy link
Contributor Author

rominf commented Aug 15, 2014

Test script used relative path to the cwd. I fixed it (see last commit).

@bpinto
Copy link
Member

bpinto commented Aug 15, 2014

Good. Now it's freezing on "# Running: ". I'll try to understand it.

Okay, I had to do the following changes to execute the tests: https://dpaste.de/GMzY
Failing scenario: https://dpaste.de/1oRS

@rominf
Copy link
Contributor Author

rominf commented Aug 15, 2014

Due scoping
source (dirname (status -f))/../dpaste.fish
should be executed after
set -g __dpaste_expires_choises

I don't know why running
source (dirname (status -f))/../dpaste.fish
in function setup don't work for you. I suggest you to ask @terlar (https://github.com/terlar/fish-tank).

Try this version.

@rominf
Copy link
Contributor Author

rominf commented Aug 15, 2014

Did you install the latest version of fish-tank BTW?

@terlar
Copy link

terlar commented Aug 16, 2014

For me the tests are passing on rominf:oh-my-fish/dpaste. Let me know if you find a way to reproduce some issue and I will look into it.

If you want to see how to use the test-framework I suggest looking into fry. That is usually what I use to develop the test-framework. I have plans to add some tests to the the actual fish-tank, but the plan to let fish-tank test itself has not been very successful so far.

@bpinto
Copy link
Member

bpinto commented Nov 20, 2014

@rominf where are we on this PR?

@rominf
Copy link
Contributor Author

rominf commented Nov 20, 2014

@bpinto
That's depends on what do you mean by "we". For me (and for others as I understood), plugin works. You had some problems as I remember. Tests didn't pass on your OS X.

@bpinto
Copy link
Member

bpinto commented Nov 20, 2014

Is this the correct output now?

.oh-my-fish:rominf-dpaste λ fish plugins/dpaste/tests/test_dpaste.fish

# Running:

.expr: not a decimal number: '1416521991N'
(standard_in) 1: parse error


Finished in 0s

1 runs, 6 assertions, 0 failures, 0 errors, 0 skips

@rominf
Copy link
Contributor Author

rominf commented Nov 20, 2014

Is this the correct output now?

.oh-my-fish:rominf-dpaste λ fish plugins/dpaste/tests/test_dpaste.fish

# Running:

.expr: not a decimal number: '1416521991N'
I'm not sure. I'll take a look tomorrow.

@rominf
Copy link
Contributor Author

rominf commented Nov 25, 2014

Well, I don't understand the meaning of this line (on my PC there is no such line):

.expr: not a decimal number: '1416521991N'

Everything else looks good.

@rominf
Copy link
Contributor Author

rominf commented Nov 25, 2014

Can you try my tests again? I've included system tests. I believe they check most of aspects of this plugin.

Enable detailed output and then run my tests:

$ set -U tank_reporter spec
$ cd plugins/dpaste/tests
$ ./test_dpaste.fish

# Running:

suite_dpaste
  ✓ test_dpaste_parse_expires
  ✓ test_dpaste_parse_expires_1
  ✓ test_dpaste_parse_expires_hour
  ✓ test_dpaste_parse_expires_never
  ✓ test_dpaste_system_file
  ✓ test_dpaste_system_file_redirect
  ✓ test_dpaste_system_stdin
  ✓ test_dpaste_system_text

Finished in 5.01s

8 runs, 16 assertions, 0 failures, 0 errors, 0 skips

@bpinto
Copy link
Member

bpinto commented Nov 26, 2014

.oh-my-fish:rominf-dpaste λ set -U tank_reporter spec
.oh-my-fish:rominf-dpaste λ cd plugins/dpaste/tests
tests:rominf-dpaste λ ./test_dpaste.fish

# Running:

suite_dpaste
  ✓ test_dpaste_parse_expires
  ✓ test_dpaste_parse_expires_1
  ✓ test_dpaste_parse_expires_hour
  ✓ test_dpaste_parse_expires_never
  ✓ test_dpaste_system_file
  ✓ test_dpaste_system_file_redirect
  ✓ test_dpaste_system_stdin
  ✓ test_dpaste_system_text
expr: not a decimal number: '1416978869N'
(standard_in) 1: parse error

Finished in 0s

8 runs, 16 assertions, 0 failures, 0 errors, 0 skips

That is possibly an issue with my fish tank version. Would you like to rebase so we can get it merged?

@terlar
Copy link

terlar commented Nov 26, 2014

What system are you running? Linux, BSD or OSX?

This is definately something with the date binary. On Linux it takes the %N to get milliseconds, but if I remember correctly OSX/BSD doesn't support this.

Everything is okay, it is only the run time that is missing because of this issue.

@rominf
Copy link
Contributor Author

rominf commented Nov 26, 2014

You can merge it, @bpinto. Now dpaste is 100% awesome, I promise you.

@bpinto
Copy link
Member

bpinto commented Nov 28, 2014

@terlar Thanks for the explanation.
@rominf You rock!
Merged.

@bpinto bpinto closed this Nov 28, 2014
bpinto added a commit that referenced this pull request Nov 28, 2014
@rominf
Copy link
Contributor Author

rominf commented Nov 28, 2014

@bpinto Thank you!

@rominf rominf deleted the dpaste branch January 5, 2015 22:18
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

Successfully merging this pull request may close these issues.

4 participants