Sha256: 30550841ad908ed6a2a85dfadca71f10592c50cff9351bfc0bf986277a57fb55

Contents?: true

Size: 1.59 KB

Versions: 1

Compression:

Stored size: 1.59 KB

Contents

#!/usr/bin/env ruby

$:.unshift File.expand_path("../../lib", __FILE__)

require "joplin"
require 'thor'


class MyCLI < Thor
  class_option :token, :type => :string #, required: true
  class_option :help, :type => :boolean
  class_option :version, :type => :boolean
  map ["-v", "--version"] => :version
  map ["-h", "--help"] => :help
  option :token, :required => true
  option :'dry-run', desc: "dry-run", aliases: '-n'
  desc :clean, "clean unused resources"
  def clean
    Joplin::token = options[:token]
    Joplin::Resource.orphaned.map { |r|
      r.delete if not options['dry-run']
      puts "Deleted #{r.id}"
    }
  end

  method_options :force => :boolean
  desc "version", "get version of program"
  def version
    puts Joplin::VERSION
  end

  desc :nb2n, "concate all notes in a notebook to one note. Possible PDF export"
  option :token, :required => true
  option :type, :type => :string
  def nb2n(query)
    Joplin::token = options[:token]
    results = Joplin.search(query, { type: 'folder' })
    nb = results[0];
    if not (nb and nb['title'] == query)
      abort "notebook #{query} not found"
    end

    notebook = Joplin::Notebook.new nb['id']
    notes = notebook.notes
    new_note = Joplin::Note.new
    new_note.title = query
    divider = %Q(<svg height="8" width="100%"><g fill="none" stroke="black" stroke-width="4"><path stroke-dasharray="20,10,5,5,5,10" d="M0 4 l415 0" /></g></svg>)

    new_note.body = notes.map { |n| "\# #{n.title}\n\n#{n.body}" }.join("\n#{divider}\n")
    new_note.save!
    puts "Saved: #{new_note.title} with id: #{new_note.id}"
  end
end

MyCLI.start(ARGV)

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
joplin-0.2.0 bin/joplin