tjgurwara99 / godocmd

A simple program to write exported definitions of Go programs packages in Markdown Format.
MIT License
1 stars 0 forks source link

format: follow directory structure #2

Open raklaptudirm opened 2 years ago

raklaptudirm commented 2 years ago

I think while showing the packages the program should follow the directory structure, as that will group similar packages together and create more intuitive documentation.

tjgurwara99 commented 2 years ago

Hey, thanks for suggesting the change! Could you maybe explain what you mean by this? If you could give a minimal example as to what that change would look like, I can put in some time aside to implement this if its feasible...

From my understanding, this is what I have got so far from the issue above:

  1. Currently the sub packages are considered packages, meaning they get included into the sorting;
  2. If package a has a sub package package b, then you want these to be formatted such that
</details><details>
    <summary> <strong> xor </strong> </summary> 

---

#####  Package xor is an encryption algorithm that operates the exclusive disjunction(XOR) ref: https://en.wikipedia.org/wiki/XOR_cipher

---
##### Functions:

1. [`Decrypt`](./cipher/xor/xor.go#L19):  Decrypt decrypts with Xor encryption
2. [`Encrypt`](./cipher/xor/xor.go#L10):  Encrypt encrypts with Xor encryption after converting each character to byte The returned value might not be readable because there is no guarantee which is within the ASCII range If using other type such as string, []int, or some other types, add the statements for converting the type to []byte.

---
</details>

which is a sub package of package cipher but appears at the root level. But if I understand it correctly, you want this to appear inside the cipher package as a sub package?

Let me know if I've understood you correctly. I believe the above is feasible, but I've been planning to make this tool into a very customisable thing (customising the format and such with a configuration file) so I think I can add this feature as a configuration as well. Let me know what you think...

raklaptudirm commented 2 years ago

Yes, you did understand me correctly.

tjgurwara99 commented 2 years ago

So I investigated this further and unfortunately the parsing function that I use is greedy, so it parses everything within a certain directory as a map of packages. I can use some other function from the same package but the behaviour would be slightly different and that would be a bigger change than I thought it would be. I will try to close this issue by implementing this feature but it would take some time. Will keep you posted.

tjgurwara99 commented 2 years ago

@raklaptudirm

Ok, I started working on this but I came across an edge case that I didn't think about before.

Consider this case:

❯ gotree
.
├── LICENSE
├── cmd
│   └── root.go
├── go.mod
├── go.sum
├── godocmd
├── main.go
└── pkg
    └── goast
        ├── experimental.go
        ├── parser.go
        └── type.go

The pkg folder is not a Go package, but it contains other Go packages (in this case, goast).

What should it look like in the output?

Another thing to consider is this

❯ gotree
.
├── LICENSE
├── cmd
│   └── root.go
├── go.mod
├── go.sum
├── godocmd
├── main.go
├── .git
│   └── some-files-but-no-go-packages
├── some_folder_without_go_packages
│   └── some-files-but-no-go-packages
└── pkg
    └── goast
        ├── experimental.go
        ├── parser.go
        └── type.go

Then the recursive design would still consider those .git folder and some_folder_without_go_packages folder to be packages and would result in the output to contain those folders. What do you think we should do with that?

raklaptudirm commented 2 years ago

The pkg folder is not a Go package, but it contains other Go packages (in this case, goast). What should it look like in the output?

The folder name should be displayed as a heading just like any other parent package. This is important because folders are used to group similar packages together, like the sort folder.

Then the recursive design would still consider those .git folder and some_folder_without_go_packages folder to be packages and would result in the output to contain those folders. What do you think we should do with that?

We should discard any folder which does not contain any .go files.

tjgurwara99 commented 2 years ago

But pkg does not contain any Go files, but it contains further folders that are go packages

raklaptudirm commented 2 years ago

By "containing a Go file", I also include any files inside subdirectories.