0

Here snippet of my elips function:

(defun log-report (filePath uniqueText)
  "Create log4j record report from any log4j (e.g.traceXXX.log) files. Log4j level MUST be in square brackets. e.g.: [DEBUG] Any text"
  (interactive "sPlease, input full path to log4j file: \nsUnique text: ")
  (message "\n\n\n\nInput path is %s" filePath)
  (if (file-exists-p filePath)
      (progn
    (if (file-exists-p FINAL_REPORT_PATH)

I start terminal. Input 2 params and my function log-report start. Nice

Here result: enter image description here

But I want to pass all parameters immediately.

Something like this:

emacs --script log-report.el -f log-report "some_log_file" "some_find_text"

Without Emacs ask me about input params.

Is it possible?

1

I suggest you introduce an option --mylog with the two required arguments.

You write a function my-log-file that processes the command line arguments after --mylog and register it in command-line-functions.

The function my-log-file checks argi whether it currently processes the option --mylog and moves the two required arguments from command-line-args-left to my-log-options. (You can implement whatever you want here.)

Demo script test.el:

(defvar my-log-options nil
  "Required command line args of --mylog read by `my-log-file-handler'.")

(defun my-log-file-handler ()
  "Move the required args of --mylog to `my-log-options'.
You can also start logging here if you want.
Logging code is not included yet."
  (when (string-match "-mylog" argi)
    (when (< (length command-line-args-left) 2)
      (user-error "Expect three arguments after --mylog"))
    (setq my-log-options
      (list (nth 0 command-line-args-left)
        (nth 1 command-line-args-left))
      command-line-args-left
      (nthcdr 2 command-line-args-left))
    t))

(add-to-list 'command-line-functions #'my-log-file-handler)

(defun show-my-log-options ()
  "Demonstrate that \"-f\" invokes `show-my-log-options' after
   all command line options are processed."
  (message "Showing my-log-options: %s" my-log-options))

If you call emacs with

emacs --script test.el --mylog one two -f show-my-log-options

you get the output

Showing my-log-options: (one two)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.